feat: 添加 Lookuper 接口和 MustLookup 方法

- 新增 Lookuper 接口,提供 Lookup 和 MustLookup 两种路径查找方式
- Accessor 接口继承 Lookuper,保持向后兼容
- MustLookup 在路径不存在时返回 Nil 访问器,简化调用代码
- 更新 fieldx.Schema 使用 Lookuper 接口,支持更灵活的数据源
- 添加 Required 字段选项,控制字段不存在时的行为
This commit is contained in:
2026-01-05 16:59:31 +08:00
parent b73099d205
commit 39da1d55dd
4 changed files with 55 additions and 15 deletions

View File

@@ -2,11 +2,20 @@ package valuex
import "reflect"
// Accessor 为参数值转换相关接口
type Accessor interface {
// Lookuper 提供基于路径查找值的能力
type Lookuper interface {
// Lookup 根据路径查找并返回对应值的访问器
Lookup(path string) (Accessor, bool)
// MustLookup 根据路径查找并直接返回对应值的访问器
// 如果路径不存在,返回 Nil 访问器(所有方法返回零值)
MustLookup(path string) Accessor
}
// Accessor 为参数值转换相关接口
type Accessor interface {
Lookuper
// Raw 返回底层的 reflect.Value
Raw() reflect.Value