package main import ( "context" "flag" "github.com/zeromicro/go-queue/kq" "github.com/zeromicro/go-zero/core/conf" "github.com/zeromicro/go-zero/core/logx" "github.com/zeromicro/go-zero/core/service" "github.com/zeromicro/go-zero/rest" "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/config" "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/handler" kq3 "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/mqs/kq" "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc" commonConfig "gitlink.org.cn/jcce-pcm/utils/nacos" ) var configFile = flag.String("f", "api/etc/pcm.yaml", "the config file") func main() { flag.Parse() var bootstrapConfig commonConfig.BootstrapConfig conf.MustLoad(*configFile, &bootstrapConfig) //解析业务配置 var c config.Config nacosConfig := bootstrapConfig.NacosConfig serviceConfigContent := nacosConfig.InitConfig(func(data string) { err := conf.LoadFromYamlBytes([]byte(data), &c) if err != nil { panic(err) } }) err := conf.LoadFromYamlBytes([]byte(serviceConfigContent), &c) if err != nil { panic(err) } // 注册到nacos nacosConfig.DiscoveryRest(&c.RestConf) serviceGroup := service.NewServiceGroup() defer serviceGroup.Stop() server := rest.MustNewServer(c.RestConf, rest.WithCors()) ctx := svc.NewServiceContext(c) // start log component logx.MustSetup(c.LogConf) ctx.Cron.Start() handler.RegisterHandlers(server, ctx) serviceGroup.Add(server) services := []service.Service{ //Listening for changes in consumption flow status kq.MustNewQueue(c.HpcConsumerConf, kq3.NewScheduleHpcMq(context.Background(), ctx)), kq.MustNewQueue(c.CloudConsumerConf, kq3.NewScheduleCloudMq(context.Background(), ctx)), kq.MustNewQueue(c.AiConsumerConf, kq3.NewScheduleAiMq(context.Background(), ctx)), //..... } for _, mq := range services { serviceGroup.Add(mq) } logx.Infof("Starting server at %s:%d...\n", c.Host, c.Port) serviceGroup.Start() }