main.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package main
  2. import (
  3. "flag"
  4. "os"
  5. "os/signal"
  6. "syscall"
  7. "time"
  8. "go-common/app/interface/main/web/conf"
  9. "go-common/app/interface/main/web/http"
  10. "go-common/app/interface/main/web/service"
  11. ecode "go-common/library/ecode/tip"
  12. "go-common/library/log"
  13. "go-common/library/net/trace"
  14. )
  15. func main() {
  16. flag.Parse()
  17. if err := conf.Init(); err != nil {
  18. log.Error("conf.Init() error(%v)", err)
  19. panic(err)
  20. }
  21. log.Init(conf.Conf.Log)
  22. trace.Init(conf.Conf.Tracer)
  23. defer trace.Close()
  24. defer log.Close()
  25. log.Info("web-interface start")
  26. // ecode
  27. ecode.Init(conf.Conf.Ecode)
  28. //server init
  29. svr := service.New(conf.Conf)
  30. http.Init(conf.Conf, svr)
  31. // signal handler
  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("web-interface get a signal %s", s.String())
  37. switch s {
  38. case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
  39. log.Info("web-interface exit")
  40. svr.Close()
  41. time.Sleep(time.Second)
  42. return
  43. case syscall.SIGHUP:
  44. // TODO reload
  45. default:
  46. return
  47. }
  48. }
  49. }