52 lines
1.1 KiB
Go
52 lines
1.1 KiB
Go
package main
|
||
|
||
import (
|
||
"context"
|
||
"flag"
|
||
"github.com/zeromicro/go-zero/core/service"
|
||
"os"
|
||
"tianyuan-api/apps/mqs/internal/config"
|
||
"tianyuan-api/apps/mqs/internal/mqs"
|
||
"tianyuan-api/apps/mqs/internal/svc"
|
||
|
||
"github.com/zeromicro/go-zero/core/conf"
|
||
"github.com/zeromicro/go-zero/rest"
|
||
)
|
||
|
||
func main() {
|
||
// 读取环境变量 ENV,默认为 "prod"
|
||
env := os.Getenv("ENV")
|
||
if env == "" {
|
||
env = "production"
|
||
}
|
||
|
||
// 根据 ENV 加载不同的配置文件
|
||
var defaultConfigFile string
|
||
if env == "development" {
|
||
defaultConfigFile = "etc/mqs.dev.yaml" // 开发环境配置
|
||
} else {
|
||
defaultConfigFile = "etc/mqs.yaml" // 生产环境配置
|
||
}
|
||
|
||
// 允许通过命令行参数覆盖配置文件路径
|
||
configFile := flag.String("f", defaultConfigFile, "the config file")
|
||
flag.Parse()
|
||
|
||
var c config.Config
|
||
conf.MustLoad(*configFile, &c)
|
||
|
||
server := rest.MustNewServer(c.RestConf)
|
||
defer server.Stop()
|
||
|
||
svcCtx := svc.NewServiceContext(c)
|
||
ctx := context.Background()
|
||
serviceGroup := service.NewServiceGroup()
|
||
defer serviceGroup.Stop()
|
||
|
||
for _, mq := range mqs.Consumers(c, ctx, svcCtx) {
|
||
serviceGroup.Add(mq)
|
||
}
|
||
|
||
serviceGroup.Start()
|
||
}
|