This commit is contained in:
乘风
2026-02-24 15:21:27 +08:00
parent b8dec9a405
commit 1860a206f9
3 changed files with 11 additions and 6 deletions

View File

@@ -6,7 +6,7 @@ GIN_MODE=debug
APP_VERSION=0.0.0 APP_VERSION=0.0.0
# 数据库(与 Next 现网一致:腾讯云 CDB soul_miniprogram # 数据库(与 Next 现网一致:腾讯云 CDB soul_miniprogram
DB_DSN=cdb_outerroot:Zhiqun1984@tcp(56b4c23f6853c.gz.cdb.myqcloud.com:14413)/soul_miniprogram?charset=utf8mb4&parseTime=True DB_DSN=souldev:RXW2FeRcRdH2GtXy@tcp(56b4c23f6853c.gz.cdb.myqcloud.com:14413)/souldev?charset=utf8mb4&parseTime=True
# 微信小程序配置 # 微信小程序配置
WECHAT_APPID=wxb8bbb2b10dec74aa WECHAT_APPID=wxb8bbb2b10dec74aa

View File

@@ -6,7 +6,7 @@ GIN_MODE=debug
APP_VERSION=0.0.0 APP_VERSION=0.0.0
# 数据库(与 Next 现网一致:腾讯云 CDB soul_miniprogram # 数据库(与 Next 现网一致:腾讯云 CDB soul_miniprogram
DB_DSN=cdb_outerroot:Zhiqun1984@tcp(56b4c23f6853c.gz.cdb.myqcloud.com:14413)/soul_miniprogram?charset=utf8mb4&parseTime=True DB_DSN=souldev:RXW2FeRcRdH2GtXy@tcp(56b4c23f6853c.gz.cdb.myqcloud.com:14413)/souldev?charset=utf8mb4&parseTime=True
# 微信小程序配置 # 微信小程序配置
WECHAT_APPID=wxb8bbb2b10dec74aa WECHAT_APPID=wxb8bbb2b10dec74aa

View File

@@ -75,12 +75,17 @@ func parseCORSOrigins() []string {
return origins return origins
} }
// Load 加载配置,端口等从 .env 读取。优先从可执行文件同目录加载 .env再试当前目录 // Load 加载配置,端口等从 env 文件读取。
// 通过 ENV_FILE 选择:.env.development默认或 .env.productionAir 运行时可用 ENV_FILE=.env.production air 切换
func Load() (*Config, error) { func Load() (*Config, error) {
if execPath, err := os.Executable(); err == nil { envFile := os.Getenv("ENV_FILE")
_ = godotenv.Load(filepath.Join(filepath.Dir(execPath), ".env")) if envFile == "" {
envFile = ".env.development"
} }
_ = godotenv.Load(".env") if execPath, err := os.Executable(); err == nil {
_ = godotenv.Load(filepath.Join(filepath.Dir(execPath), envFile))
}
_ = godotenv.Load(envFile)
port := os.Getenv("PORT") port := os.Getenv("PORT")
if port == "" { if port == "" {