|
|
|
|
|
//
|
|
|
|
|
|
// cfg.go
|
|
|
|
|
|
// Copyright (C) 2024 veypi <i@veypi.com>
|
|
|
|
|
|
// 2025-03-04 16:08:06
|
|
|
|
|
|
// Distributed under terms of the MIT license.
|
|
|
|
|
|
//
|
|
|
|
|
|
// 本地配置文件 - 仅包含启动必需的配置
|
|
|
|
|
|
// 其他配置请在部署后通过管理后台设置(数据库存储)
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
package cfg
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/veypi/vigo/contrib/config"
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
// Options 本地配置选项(启动时加载,修改需重启)
|
|
|
|
|
|
type Options struct {
|
|
|
|
|
|
// === 基础设施(必须)===
|
|
|
|
|
|
DB config.Database `json:"db"`
|
|
|
|
|
|
Redis config.Redis `json:"redis" usage:"Redis 配置,addr: memory 使用内存模式"`
|
|
|
|
|
|
Key config.Key `json:"key" usage:"系统密钥,用于加密敏感数据(建议 32 位以上)"`
|
|
|
|
|
|
|
|
|
|
|
|
// === 文件存储 ===
|
|
|
|
|
|
StoragePath string `json:"storage_path" usage:"文件存储路径"`
|
|
|
|
|
|
|
|
|
|
|
|
// === JWT 配置(安全敏感,保留在本地) ===
|
|
|
|
|
|
JWT JWTConfig `json:"jwt" usage:"JWT 配置"`
|
|
|
|
|
|
|
|
|
|
|
|
// === 初始管理员(无人值守部署时使用)===
|
|
|
|
|
|
// 当用户表为空且 username/password 都有值时,启动自动创建该管理员
|
|
|
|
|
|
// 如果 password 为空,则保持默认逻辑:第一个注册用户成为 admin
|
|
|
|
|
|
InitAdmin InitAdminConfig `json:"init_admin" usage:"初始管理员配置"`
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// JWTConfig JWT 配置
|
|
|
|
|
|
type JWTConfig struct {
|
|
|
|
|
|
Secret string `json:"secret" usage:"JWT 密钥(为空则使用 Key)"`
|
|
|
|
|
|
AccessExpiry time.Duration `json:"access_expiry" usage:"Access Token 有效期"`
|
|
|
|
|
|
RefreshExpiry time.Duration `json:"refresh_expiry" usage:"Refresh Token 有效期"`
|
|
|
|
|
|
Issuer string `json:"issuer" usage:"JWT 签发者"`
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// InitAdminConfig 初始管理员配置
|
|
|
|
|
|
type InitAdminConfig struct {
|
|
|
|
|
|
Username string `json:"username" usage:"管理员用户名"`
|
|
|
|
|
|
Password string `json:"password" usage:"管理员密码(为空则禁用自动创建)"`
|
|
|
|
|
|
Email string `json:"email" usage:"管理员邮箱"`
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Config 全局配置实例
|
|
|
|
|
|
var Config = &Options{
|
|
|
|
|
|
DB: config.Database{
|
|
|
|
|
|
Type: "mysql",
|
|
|
|
|
|
DSN: "root:123456@tcp(127.0.0.1:3306)/vbase?charset=utf8&parseTime=True&loc=Local",
|
|
|
|
|
|
},
|
|
|
|
|
|
Redis: config.Redis{
|
|
|
|
|
|
Addr: "memory",
|
|
|
|
|
|
},
|
|
|
|
|
|
Key: "your-secret-key-change-in-production-min-32-characters",
|
|
|
|
|
|
StoragePath: "./data",
|
|
|
|
|
|
JWT: JWTConfig{
|
|
|
|
|
|
Secret: "",
|
|
|
|
|
|
AccessExpiry: time.Hour,
|
|
|
|
|
|
RefreshExpiry: 30 * 24 * time.Hour,
|
|
|
|
|
|
Issuer: "vbase",
|
|
|
|
|
|
},
|
|
|
|
|
|
InitAdmin: InitAdminConfig{
|
|
|
|
|
|
Username: "admin",
|
|
|
|
|
|
Password: "123456", // 为空表示不自动创建,第一个注册用户成为 admin
|
|
|
|
|
|
Email: "admin@example.com",
|
|
|
|
|
|
},
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var DB = Config.DB.Client
|