main.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package main
  2. import (
  3. "context"
  4. "flag"
  5. "os"
  6. "os/signal"
  7. "syscall"
  8. "time"
  9. "go-common/app/service/bbq/video-image/conf"
  10. "go-common/app/service/bbq/video-image/server/grpc"
  11. "go-common/app/service/bbq/video-image/server/http"
  12. "go-common/app/service/bbq/video-image/service"
  13. // ecode "go-common/library/ecode/tip"
  14. "go-common/library/log"
  15. // "go-common/library/net/trace"
  16. )
  17. func main() {
  18. flag.Parse()
  19. if err := conf.Init(); err != nil {
  20. panic(err)
  21. }
  22. log.Init(conf.Conf.Log)
  23. defer log.Close()
  24. log.Info("start")
  25. // dev环境先不要
  26. // trace.Init(conf.Conf.Tracer)
  27. // defer trace.Close()
  28. // ecode.Init(conf.Conf.Ecode)
  29. serv := service.New(conf.Conf)
  30. gserv := grpc.New(conf.Conf.RPC, serv)
  31. http.Init(conf.Conf, serv)
  32. c := make(chan os.Signal, 1)
  33. signal.Notify(c, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
  34. ctx, cancel := context.WithTimeout(context.Background(), time.Second*3)
  35. defer cancel()
  36. for {
  37. s := <-c
  38. log.Info("get a signal %s", s.String())
  39. switch s {
  40. case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
  41. gserv.Shutdown(ctx)
  42. log.Info("exit")
  43. return
  44. case syscall.SIGHUP:
  45. default:
  46. return
  47. }
  48. }
  49. }