Files
contracts/base/res_configure.go
T
2026-05-15 09:04:12 +08:00

49 lines
1.4 KiB
Go

package base
import (
"git.fsdpf.net/go/reflux"
"git.fsdpf.net/go/reflux/valuex"
)
// role_uuid => value
type ResRoleValue map[string]string
type ResConfigure struct {
Uuid string `db:"uuid"`
ResourceUuid string `db:"resource_uuid"`
Key string `db:"key"`
Value string `db:"value"`
Label string `db:"label"`
Type string `db:"type"`
IsPrivate bool `db:"isPrivate"`
Desc string `db:"desc"`
RoleValues []ResRoleValue `db:"role_values"`
UpdatedAt string `db:"updated_at"`
CreatedAt string `db:"created_at"`
}
// GetValueByRoles 根据角色优先级获取配置值
//
// - roles: 角色UUIDs
//
// 返回: valuex.Accessor 对象和是否找到角色特定值的标志
func (rc *ResConfigure) GetValueByRoles(roles ...string) (valuex.Accessor, bool) {
// 如果没有角色值配置或没有传入角色,返回默认值
if len(rc.RoleValues) == 0 || len(roles) == 0 {
return reflux.New(rc.Value), false
}
for _, rv := range rc.RoleValues {
for _, role := range roles {
if value, exists := rv[role]; exists {
return reflux.New(value), true
}
}
}
// 没有找到匹配的角色值,返回默认值
return reflux.New(rc.Value), false
}
type GetResConfigure func(key string, roles ...string) (valuex.Accessor, bool)