You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
OneAuth/cfg/cfg.go

75 lines
2.5 KiB
Go

11 months ago
//
// cfg.go
// Copyright (C) 2024 veypi <i@veypi.com>
// 2025-03-04 16:08:06
// Distributed under terms of the MIT license.
//
// 本地配置文件 - 仅包含启动必需的配置
// 其他配置请在部署后通过管理后台设置(数据库存储)
//
11 months ago
package cfg
6 months ago
import (
"time"
1 week ago
"github.com/veypi/vigo/contrib/config"
6 months ago
)
// Options 本地配置选项(启动时加载,修改需重启)
10 months ago
type Options struct {
// === 基础设施(必须)===
DSN string `json:"dsn" usage:"数据库连接字符串"` // Data Source Name
DB string `json:"db" usage:"数据库类型: mysql, postgres, sqlite"`
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:"管理员邮箱"`
11 months ago
}
// Config 全局配置实例
var Config = &Options{
DB: "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",
},
}