main.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package main
  2. import (
  3. "context"
  4. "flag"
  5. "go-common/library/conf/paladin"
  6. "os"
  7. "os/signal"
  8. "syscall"
  9. "time"
  10. "go-common/app/service/bbq/user/internal/conf"
  11. "go-common/app/service/bbq/user/internal/server/grpc"
  12. "go-common/app/service/bbq/user/internal/server/http"
  13. "go-common/app/service/bbq/user/internal/service"
  14. ecode "go-common/library/ecode/tip"
  15. "go-common/library/log"
  16. "go-common/library/net/trace"
  17. )
  18. var (
  19. _confName string
  20. _unameConfName string
  21. )
  22. func init() {
  23. //线下使用
  24. flag.StringVar(&_confName, "conf_name", "user.toml", "default config filename")
  25. flag.StringVar(&_unameConfName, "uname_conf_name", "uname.json", "default config filename")
  26. }
  27. func main() {
  28. flag.Parse()
  29. if err := paladin.Init(); err != nil {
  30. panic(err)
  31. }
  32. if err := paladin.Watch(_confName, conf.Conf); err != nil {
  33. panic(err)
  34. }
  35. if err := paladin.Watch(_unameConfName, conf.UnameConf); err != nil {
  36. panic(err)
  37. }
  38. log.Init(conf.Conf.Log)
  39. defer log.Close()
  40. log.Info("user-service start")
  41. trace.Init(conf.Conf.Tracer)
  42. defer trace.Close()
  43. ecode.Init(conf.Conf.Ecode)
  44. svc := service.New(conf.Conf)
  45. grpcServ := grpc.New(conf.Conf.GRPC, svc)
  46. http.Init(conf.Conf, svc)
  47. c := make(chan os.Signal, 1)
  48. signal.Notify(c, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
  49. for {
  50. s := <-c
  51. log.Info("get a signal %s", s.String())
  52. switch s {
  53. case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
  54. svc.Close()
  55. grpcServ.Shutdown(context.Background())
  56. log.Info("user-service exit")
  57. time.Sleep(time.Second)
  58. return
  59. case syscall.SIGHUP:
  60. default:
  61. return
  62. }
  63. }
  64. }