重构: base 包资源核心类型迁移到 req/resx,新增 res_watcher/res_api_param
base/resource.go、resource_hooks.go、resource_test.go、query_field.go 删除,ResField 等具体实现搬到 req/resx(见 res_field.go 里的类型别名)。res_listener.go 替换成 res_watcher.go,对应资源变更监听概念改名。新增 res_api_param.go 及配套测试(ResApi 参数建模,给 MCP tool 的 JSON Schema 生成用)。
This commit is contained in:
+21
-3
@@ -1,6 +1,8 @@
|
||||
package base
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"git.fsdpf.net/go/reflux"
|
||||
"git.fsdpf.net/go/reflux/valuex"
|
||||
)
|
||||
@@ -30,19 +32,35 @@ type ResConfigure struct {
|
||||
func (rc *ResConfigure) GetValueByRoles(roles ...string) (valuex.Accessor, bool) {
|
||||
// 如果没有角色值配置或没有传入角色,返回默认值
|
||||
if len(rc.RoleValues) == 0 || len(roles) == 0 {
|
||||
return reflux.New(rc.Value), false
|
||||
return reflux.New(rc.toTyped(rc.Value)), true
|
||||
}
|
||||
|
||||
for _, rv := range rc.RoleValues {
|
||||
for _, role := range roles {
|
||||
if value, exists := rv[role]; exists {
|
||||
return reflux.New(value), true
|
||||
return reflux.New(rc.toTyped(value)), true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 没有找到匹配的角色值,返回默认值
|
||||
return reflux.New(rc.Value), false
|
||||
return reflux.New(rc.toTyped(rc.Value)), false
|
||||
}
|
||||
|
||||
func (rc *ResConfigure) toTyped(s string) any {
|
||||
switch rc.Type {
|
||||
case "json":
|
||||
var v map[string]any
|
||||
if json.Unmarshal([]byte(s), &v) == nil {
|
||||
return v
|
||||
}
|
||||
case "array":
|
||||
var v []any
|
||||
if json.Unmarshal([]byte(s), &v) == nil {
|
||||
return v
|
||||
}
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
type GetResConfigure func(key string, roles ...string) (valuex.Accessor, bool)
|
||||
|
||||
Reference in New Issue
Block a user