// Package config 负责从环境变量加载应用配置。 package config import ( "os" "strconv" ) // Config 应用全局配置,优先读取环境变量,未设置时使用默认值。 type Config struct { Port int // HTTP 监听端口,默认 8080,环境变量 GEN2D_PORT Mode string // Gin 运行模式 (debug/release),环境变量 GEN2D_MODE MaxFileSize int64 // 上传文件大小上限(字节),默认 10MB } // Load 从环境变量加载配置并返回。 func Load() *Config { cfg := &Config{ Port: 8080, Mode: "debug", MaxFileSize: 10 << 20, // 10MB } if port := os.Getenv("GEN2D_PORT"); port != "" { if p, err := strconv.Atoi(port); err == nil { cfg.Port = p } } if mode := os.Getenv("GEN2D_MODE"); mode != "" { cfg.Mode = mode } return cfg }