threemarket.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package main
  2. import (
  3. "flag"
  4. "fmt"
  5. "os"
  6. "os/signal"
  7. "syscall"
  8. "bp.jydev.jianyu360.cn/ApplicationCenter/threeMarket/api/internal/config"
  9. "bp.jydev.jianyu360.cn/ApplicationCenter/threeMarket/api/internal/handler"
  10. "bp.jydev.jianyu360.cn/ApplicationCenter/threeMarket/api/internal/svc"
  11. "bp.jydev.jianyu360.cn/ApplicationCenter/threeMarket/public/service"
  12. "bp.jydev.jianyu360.cn/ApplicationCenter/threeMarket/rpc/threemarket"
  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/threemarket.yaml", "the config file")
  19. func main() {
  20. flag.Parse()
  21. var c config.Config
  22. conf.MustLoad(*configFile, &c)
  23. ctx := svc.NewServiceContext(c)
  24. server := rest.MustNewServer(c.RestConf)
  25. defer server.Stop()
  26. service.ThreemarketRpc = threemarket.NewThreeMarket(zrpc.MustNewClient(c.ThreeMarketRpcConf))
  27. handler.RegisterHandlers(server, ctx)
  28. closeNotify, err := node.NewNode(c.GatewayRpcConf.Etcd.Hosts[0]).Register(c.ThreeMarketRpcConf.Etcd.Key, fmt.Sprint(c.Port))
  29. if err != nil {
  30. panic(err)
  31. }
  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. }