91 lines
1.5 KiB
Go
91 lines
1.5 KiB
Go
package config
|
|
|
|
import "time"
|
|
|
|
// Config 系統配置
|
|
type Config struct {
|
|
// Database 資料庫配置
|
|
Database DatabaseConfig
|
|
|
|
// Redis 快取配置
|
|
Redis RedisConfig
|
|
|
|
// RBAC 配置
|
|
RBAC RBACConfig
|
|
|
|
// Role 角色配置
|
|
Role RoleConfig
|
|
}
|
|
|
|
// DatabaseConfig 資料庫配置
|
|
type DatabaseConfig struct {
|
|
Host string
|
|
Port int
|
|
Username string
|
|
Password string
|
|
Database string
|
|
MaxIdle int
|
|
MaxOpen int
|
|
}
|
|
|
|
// RedisConfig Redis 配置
|
|
type RedisConfig struct {
|
|
Host string
|
|
Port int
|
|
Password string
|
|
DB int
|
|
|
|
// Cache TTL
|
|
PermissionTreeTTL time.Duration
|
|
UserPermissionTTL time.Duration
|
|
RolePolicyTTL time.Duration
|
|
}
|
|
|
|
// RBACConfig RBAC 配置
|
|
type RBACConfig struct {
|
|
ModelPath string
|
|
SyncPeriod time.Duration
|
|
EnableCache 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{
|
|
Redis: RedisConfig{
|
|
PermissionTreeTTL: 10 * time.Minute,
|
|
UserPermissionTTL: 5 * time.Minute,
|
|
RolePolicyTTL: 10 * time.Minute,
|
|
},
|
|
RBAC: RBACConfig{
|
|
ModelPath: "./rbac_model.conf",
|
|
SyncPeriod: 30 * time.Second,
|
|
EnableCache: true,
|
|
},
|
|
Role: RoleConfig{
|
|
UIDPrefix: "AM",
|
|
UIDLength: 6,
|
|
AdminRoleUID: "AM000000",
|
|
AdminUserUID: "B000000",
|
|
DefaultRoleName: "user",
|
|
},
|
|
}
|
|
}
|