config: GIN_MODE 改为环境变量配置 + Load() 自动加载 .env
main.go 硬编码 gin.ReleaseMode 改成读 cfg.GinMode(默认 release),
方便生产/调试切换 debug/release/test。Load() 开头先调 loadDotenv
(".env"): 缺文件静默跳过,shell env 优先于 .env,跳过注释/空行/
无 '=' 行并 slog.Warn。仅用标准库,不引新依赖。
验证:
- go build / go vet / go test 全部通过
- shell env 覆盖 .env (LISTEN_ADDR=:19090 覆盖 .env 的 :18080)
- 仅 .env 时正确加载 (监听 18080, GIN_MODE=debug 输出 [GIN-debug])
- 无 .env 且无 shell env 时清晰报错 ADMIN_TOKENS is not set
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -31,6 +31,9 @@ LOG_LEVEL=info
|
||||
# Log format: text (terminal) or json (log file; default: text)
|
||||
LOG_FORMAT=text
|
||||
|
||||
# Gin mode: debug, release, test (default: release)
|
||||
GIN_MODE=release
|
||||
|
||||
# Analyzer heuristic thresholds (defaults shown)
|
||||
ANALYZER_DATA_SKEW_RATIO=3.0
|
||||
ANALYZER_GC_PRESSURE_RATIO=0.1
|
||||
|
||||
Reference in New Issue
Block a user