main.go 1010 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package main
  2. import (
  3. "context"
  4. "flag"
  5. "os"
  6. "os/signal"
  7. "syscall"
  8. "time"
  9. "go-common/app/interface/main/report-click/conf"
  10. "go-common/app/interface/main/report-click/http"
  11. "go-common/library/log"
  12. "go-common/library/net/trace"
  13. )
  14. func main() {
  15. flag.Parse()
  16. if err := conf.Init(); err != nil {
  17. log.Error("conf.Init() error(%v)", err)
  18. panic(err)
  19. }
  20. log.Init(conf.Conf.Xlog)
  21. defer log.Close()
  22. log.Info("report-click start")
  23. trace.Init(conf.Conf.Tracer)
  24. defer trace.Close()
  25. engine := http.New(conf.Conf)
  26. c := make(chan os.Signal, 1)
  27. signal.Notify(c, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
  28. for {
  29. s := <-c
  30. log.Info("report-click get a signal %s", s.String())
  31. switch s {
  32. case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
  33. ctx, cancel := context.WithTimeout(context.Background(), time.Second*60)
  34. defer cancel()
  35. engine.Shutdown(ctx)
  36. log.Info("report-click exit")
  37. return
  38. case syscall.SIGHUP:
  39. // TODO reload
  40. default:
  41. return
  42. }
  43. }
  44. }