main.go 902 B

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