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:
tao.chen
2026-07-13 13:48:35 +08:00
co-authored by Claude
parent 756a88a800
commit 7f8960823b
3 changed files with 82 additions and 2 deletions
+1 -1
View File
@@ -65,7 +65,7 @@ func run() error {
defer db.Close()
logger.Info("storage.open", "path", cfg.SQLitePath)
gin.SetMode(gin.ReleaseMode)
gin.SetMode(cfg.GinMode)
r := gin.New()
r.Use(gin.Recovery())