main.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package main
  2. import (
  3. "context"
  4. "flag"
  5. "os"
  6. "os/signal"
  7. "syscall"
  8. "time"
  9. "go-common/app/admin/bbq/comment/internal/server/http"
  10. "go-common/app/admin/bbq/comment/internal/service"
  11. "go-common/library/conf/paladin"
  12. ecode "go-common/library/ecode/tip"
  13. "go-common/library/log"
  14. )
  15. func main() {
  16. flag.Parse()
  17. if err := paladin.Init(); err != nil {
  18. panic(err)
  19. }
  20. log.Init(nil) // debug flag: log.dir={path}
  21. defer log.Close()
  22. log.Info("comment-admin start")
  23. ecode.Init(nil)
  24. svc := service.New()
  25. httpSrv := http.New(svc)
  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("get a signal %s", s.String())
  31. switch s {
  32. case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
  33. ctx, cancel := context.WithTimeout(context.Background(), 35*time.Second)
  34. defer cancel()
  35. httpSrv.Shutdown(ctx)
  36. log.Info("comment-admin exit")
  37. svc.Close()
  38. time.Sleep(time.Second)
  39. return
  40. case syscall.SIGHUP:
  41. default:
  42. return
  43. }
  44. }
  45. }