区分环境

This commit is contained in:
2024-10-02 11:27:51 +08:00
parent ab842d8694
commit b8d9a72dac
30 changed files with 626 additions and 181 deletions

View File

@@ -4,6 +4,7 @@ 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"
@@ -12,9 +13,23 @@ import (
"github.com/zeromicro/go-zero/rest"
)
var configFile = flag.String("f", "etc/mqs.yaml", "the config file")
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