main.go 852 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package main
  2. import (
  3. "flag"
  4. "os"
  5. "os/signal"
  6. "syscall"
  7. "time"
  8. "go-common/app/interface/main/laser/conf"
  9. "go-common/app/interface/main/laser/http"
  10. "go-common/library/log"
  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. log.Init(conf.Conf.Log)
  19. defer log.Close()
  20. log.Info("laser-interface start")
  21. http.Init(conf.Conf)
  22. // signal handler
  23. c := make(chan os.Signal, 1)
  24. signal.Notify(c, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
  25. for {
  26. s := <-c
  27. log.Info("laser-interface get a signal %s", s.String())
  28. switch s {
  29. case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGSTOP, syscall.SIGINT:
  30. time.Sleep(time.Second * 2)
  31. log.Info("laser-interface exit")
  32. return
  33. case syscall.SIGHUP:
  34. // TODO reload
  35. default:
  36. return
  37. }
  38. }
  39. }