main.go 976 B

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