main.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package main
  2. import (
  3. "flag"
  4. "log"
  5. "os"
  6. "os/signal"
  7. "syscall"
  8. apiv1 "go-common/app/service/main/dapper-query/api/v1"
  9. "go-common/app/service/main/dapper-query/conf"
  10. "go-common/app/service/main/dapper-query/service"
  11. "go-common/app/service/main/dapper-query/util"
  12. xlog "go-common/library/log"
  13. bm "go-common/library/net/http/blademaster"
  14. )
  15. func main() {
  16. if !flag.Parsed() {
  17. flag.Parse()
  18. }
  19. // load config file
  20. if err := conf.Init(); err != nil {
  21. log.Fatalf("init config error: %s", err)
  22. }
  23. // init xlog
  24. xlog.Init(nil)
  25. defer xlog.Close()
  26. xlog.Info("dapper-service start")
  27. // new dapper service
  28. srv, err := service.New(conf.Conf)
  29. if err != nil {
  30. log.Fatalf("new dapper service error: %s", err)
  31. }
  32. // init blademaster server
  33. engine := bm.NewServer(nil)
  34. engine.Use(bm.Recovery(), bm.Logger())
  35. engine.Ping(func(*bm.Context) {})
  36. engine.Inject("^/x/internal/dapper/ops-log", util.SessionIDMiddleware)
  37. apiv1.RegisterDapperQueryBMServer(engine, srv)
  38. if err := engine.Start(); err != nil {
  39. log.Fatalf("start bm server error: %s", err)
  40. }
  41. sch := make(chan os.Signal, 1)
  42. signal.Notify(sch, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
  43. s := <-sch
  44. // program exit
  45. xlog.Info("dapper-service get a signal %s", s.String())
  46. xlog.Info("dapper-service exit")
  47. }