chore: initial import 萌邮 MengPost (React+Vite + Go+Gin)
Made-with: Cursor
This commit is contained in:
30
mengpost-backend/config/config.go
Normal file
30
mengpost-backend/config/config.go
Normal file
@@ -0,0 +1,30 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user