main.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package main
  2. import (
  3. "flag"
  4. "log"
  5. "os"
  6. "go-common/app/service/main/dapper/collector"
  7. "go-common/app/service/main/dapper/conf"
  8. "go-common/app/service/main/dapper/pkg/util"
  9. xlog "go-common/library/log"
  10. )
  11. func main() {
  12. if !flag.Parsed() {
  13. flag.Parse()
  14. }
  15. // load config file
  16. if err := conf.Init(); err != nil {
  17. log.Fatalf("init config error: %s", err)
  18. }
  19. // init xlog
  20. xlog.Init(conf.Conf.Log)
  21. defer xlog.Close()
  22. xlog.Info("dapper-service starting")
  23. // new collector service
  24. srv, err := collector.New(conf.Conf)
  25. if err != nil {
  26. log.Fatalf("new dapper service error: %s", err)
  27. }
  28. if err := srv.ListenAndStart(); err != nil {
  29. log.Fatalf("start dapper service error: %s", err)
  30. }
  31. //hsvr := http.New(srv)
  32. //if err := hsvr.Start(); err != nil {
  33. // log.Fatalf("start dapper http server error: %s", err)
  34. //}
  35. util.HandlerExit(func(s os.Signal) int {
  36. xlog.Info("dapper-service get a signal %s", s.String())
  37. if err := srv.Close(); err != nil {
  38. xlog.Info("dapper-service exit, error: %s", err)
  39. return 1
  40. }
  41. xlog.Info("dapper-service exit")
  42. return 0
  43. })
  44. }