main.go 1.1 KB

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