marketing.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package main
  2. import (
  3. "flag"
  4. "fmt"
  5. "os"
  6. "os/signal"
  7. "syscall"
  8. "bp.jydev.jianyu360.cn/ApplicationCenter/marketing/api/internal/config"
  9. "bp.jydev.jianyu360.cn/ApplicationCenter/marketing/api/internal/handler"
  10. "bp.jydev.jianyu360.cn/ApplicationCenter/marketing/api/internal/svc"
  11. "bp.jydev.jianyu360.cn/ApplicationCenter/marketing/public/service"
  12. "bp.jydev.jianyu360.cn/ApplicationCenter/marketing/rpc/marketing"
  13. "bp.jydev.jianyu360.cn/BaseService/gateway/core/node"
  14. "github.com/zeromicro/go-zero/core/conf"
  15. "github.com/zeromicro/go-zero/rest"
  16. "github.com/zeromicro/go-zero/zrpc"
  17. )
  18. var configFile = flag.String("f", "etc/marketing.yaml", "the config file")
  19. func main() {
  20. flag.Parse()
  21. var c config.Config
  22. conf.MustLoad(*configFile, &c)
  23. service.MarketingRpc = marketing.NewMarketing(zrpc.MustNewClient(c.MarketingRpcConf))
  24. ctx := svc.NewServiceContext(c)
  25. server := rest.MustNewServer(c.RestConf)
  26. closeNotify, err := node.NewNode(c.GatewayRpcConf.Etcd.Hosts[0]).Register(c.MarketingRpcConf.Etcd.Key, fmt.Sprint(c.Port))
  27. if err != nil {
  28. panic(err)
  29. }
  30. defer server.Stop()
  31. handler.RegisterHandlers(server, ctx)
  32. fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port)
  33. go func() {
  34. server.Start()
  35. }()
  36. quit := make(chan os.Signal, 1)
  37. signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
  38. <-quit
  39. closeNotify()
  40. }