main.go 1.1 KB

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