main.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package main
  2. import (
  3. "flag"
  4. "os"
  5. "os/signal"
  6. "syscall"
  7. "time"
  8. "go-common/app/service/main/ugcpay-rank/internal/conf"
  9. "go-common/app/service/main/ugcpay-rank/internal/server/grpc"
  10. "go-common/app/service/main/ugcpay-rank/internal/server/http"
  11. "go-common/app/service/main/ugcpay-rank/internal/service"
  12. ecode "go-common/library/ecode/tip"
  13. "go-common/library/log"
  14. "go-common/library/net/trace"
  15. )
  16. func main() {
  17. flag.Parse()
  18. if err := conf.Init(); err != nil {
  19. panic(err)
  20. }
  21. log.Init(conf.Conf.Log)
  22. defer log.Close()
  23. trace.Init(conf.Conf.Tracer)
  24. defer trace.Close()
  25. log.Info("ugcpay-rank-service start")
  26. ecode.Init(conf.Conf.Ecode)
  27. svc := service.New(conf.Conf)
  28. http.Init(svc)
  29. grpc.New(nil, svc)
  30. c := make(chan os.Signal, 1)
  31. signal.Notify(c, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
  32. for {
  33. s := <-c
  34. log.Info("get a signal %s", s.String())
  35. switch s {
  36. case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
  37. svc.Close()
  38. log.Info("ugcpay-rank-service exit")
  39. time.Sleep(time.Second)
  40. return
  41. case syscall.SIGHUP:
  42. default:
  43. return
  44. }
  45. }
  46. }