main.go 1008 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package main
  2. import (
  3. "flag"
  4. "os"
  5. "os/signal"
  6. "syscall"
  7. "time"
  8. "go-common/app/interface/live/app-blink/conf"
  9. "go-common/app/interface/live/app-blink/server/http"
  10. "go-common/app/interface/live/app-blink/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. panic(err)
  19. }
  20. log.Init(conf.Conf.Log)
  21. defer log.Close()
  22. log.Info("app-blink-interface start")
  23. trace.Init(conf.Conf.Tracer)
  24. defer trace.Close()
  25. ecode.Init(conf.Conf.Ecode)
  26. svc := service.New(conf.Conf)
  27. http.Init(conf.Conf, svc)
  28. c := make(chan os.Signal, 1)
  29. signal.Notify(c, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
  30. for {
  31. s := <-c
  32. log.Info("get a signal %s", s.String())
  33. switch s {
  34. case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
  35. svc.Close()
  36. log.Info("app-blink-interface exit")
  37. time.Sleep(time.Second)
  38. return
  39. case syscall.SIGHUP:
  40. default:
  41. return
  42. }
  43. }
  44. }