main.go 997 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package main
  2. import (
  3. "flag"
  4. "os"
  5. "os/signal"
  6. "syscall"
  7. "go-common/app/admin/main/config/conf"
  8. "go-common/app/admin/main/config/http"
  9. "go-common/app/admin/main/config/service"
  10. "go-common/library/log"
  11. // register config lint
  12. _ "go-common/app/admin/main/config/pkg/lint/json"
  13. _ "go-common/app/admin/main/config/pkg/lint/toml"
  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. // init log
  22. log.Init(conf.Conf.Log)
  23. defer log.Close()
  24. log.Info("config-admin start")
  25. svr := service.New(conf.Conf)
  26. http.Init(conf.Conf, svr)
  27. c := make(chan os.Signal, 1)
  28. signal.Notify(c, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
  29. for {
  30. s := <-c
  31. log.Info("config-admin get a signal %s", s.String())
  32. switch s {
  33. case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
  34. svr.Close()
  35. log.Info("config-admin exit")
  36. return
  37. case syscall.SIGHUP:
  38. // TODO reload
  39. default:
  40. return
  41. }
  42. }
  43. }