Files
mengpost/mengpost-backend/config/config.go
2026-04-17 22:27:57 +08:00

31 lines
637 B
Go

package config
import (
"os"
)
// Config 存放运行期配置, 所有值均可通过环境变量覆盖.
type Config struct {
Port string // HTTP 监听端口
DBPath string // SQLite 数据库路径
Token string // 管理员访问 token
LogLevel string
}
// Load 读取环境变量生成配置, 未设置时使用默认值.
func Load() *Config {
return &Config{
Port: env("MP_PORT", "8787"),
DBPath: env("MP_DB", "mengpost.db"),
Token: env("MP_TOKEN", "shumengya520"),
LogLevel: env("MP_LOG", "info"),
}
}
func env(k, def string) string {
if v := os.Getenv(k); v != "" {
return v
}
return def
}