73 lines
1.2 KiB
Go
73 lines
1.2 KiB
Go
package config
|
|
|
|
import "time"
|
|
|
|
// Config 系統配置
|
|
type Config struct {
|
|
// MongoDB 配置
|
|
Mongo MongoConfig
|
|
|
|
// Redis 快取配置
|
|
Redis RedisConfig
|
|
|
|
// Role 角色配置
|
|
Role RoleConfig
|
|
}
|
|
|
|
// MongoConfig MongoDB 配置
|
|
type MongoConfig struct {
|
|
URI string // mongodb://user:password@host:port
|
|
Database string
|
|
Timeout time.Duration
|
|
}
|
|
|
|
// RedisConfig Redis 配置 (go-zero 格式)
|
|
type RedisConfig struct {
|
|
Host string
|
|
Type string // node, cluster
|
|
Pass string
|
|
Tls bool
|
|
}
|
|
|
|
// RoleConfig 角色配置
|
|
type RoleConfig struct {
|
|
// UID 前綴 (例如: AM, RL)
|
|
UIDPrefix string
|
|
|
|
// UID 數字長度
|
|
UIDLength int
|
|
|
|
// 管理員角色 UID
|
|
AdminRoleUID string
|
|
|
|
// 管理員用戶 UID
|
|
AdminUserUID string
|
|
|
|
// 預設角色名稱
|
|
DefaultRoleName string
|
|
}
|
|
|
|
// DefaultConfig 預設配置
|
|
func DefaultConfig() Config {
|
|
return Config{
|
|
Mongo: MongoConfig{
|
|
URI: "mongodb://localhost:27017",
|
|
Database: "permission",
|
|
Timeout: 10 * time.Second,
|
|
},
|
|
Redis: RedisConfig{
|
|
Host: "localhost:6379",
|
|
Type: "node",
|
|
Pass: "",
|
|
Tls: false,
|
|
},
|
|
Role: RoleConfig{
|
|
UIDPrefix: "AM",
|
|
UIDLength: 6,
|
|
AdminRoleUID: "AM000000",
|
|
AdminUserUID: "B000000",
|
|
DefaultRoleName: "user",
|
|
},
|
|
}
|
|
}
|