main.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package main
  2. import (
  3. "flag"
  4. "os"
  5. "os/signal"
  6. "syscall"
  7. "time"
  8. "go-common/app/interface/openplatform/article/conf"
  9. "go-common/app/interface/openplatform/article/http"
  10. artrpc "go-common/app/interface/openplatform/article/rpc/server"
  11. "go-common/app/interface/openplatform/article/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. log.Error("conf.Init() error(%+v)", err)
  20. panic(err)
  21. }
  22. log.Init(conf.Conf.Log)
  23. trace.Init(conf.Conf.Tracer)
  24. defer trace.Close()
  25. defer log.Close()
  26. log.Info("article start")
  27. // server init
  28. ecode.Init(conf.Conf.Ecode)
  29. svr := service.New(conf.Conf)
  30. http.Init(conf.Conf, svr)
  31. rpcSvr := artrpc.New(svr)
  32. // signal handler
  33. c := make(chan os.Signal, 1)
  34. signal.Notify(c, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
  35. for {
  36. s := <-c
  37. log.Info("article get a signal %s", s.String())
  38. switch s {
  39. case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGSTOP, syscall.SIGINT:
  40. log.Info("article exit")
  41. rpcSvr.Close()
  42. svr.Close()
  43. time.Sleep(time.Second)
  44. return
  45. case syscall.SIGHUP:
  46. // TODO reload
  47. default:
  48. return
  49. }
  50. }
  51. }