区分环境
This commit is contained in:
@@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"tianyuan-api/apps/sentinel/internal/config"
|
||||
productServer "tianyuan-api/apps/sentinel/internal/server/product"
|
||||
@@ -19,9 +20,23 @@ import (
|
||||
"google.golang.org/grpc/reflection"
|
||||
)
|
||||
|
||||
var configFile = flag.String("f", "etc/sentinel.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/sentinel.dev.yaml" // 开发环境配置
|
||||
} else {
|
||||
defaultConfigFile = "etc/sentinel.yaml" // 生产环境配置
|
||||
}
|
||||
|
||||
// 允许通过命令行参数覆盖配置文件路径
|
||||
configFile := flag.String("f", defaultConfigFile, "the config file")
|
||||
flag.Parse()
|
||||
|
||||
var c config.Config
|
||||
|
||||
Reference in New Issue
Block a user