diff --git a/options.go b/options.go index d5dc976..debc880 100644 --- a/options.go +++ b/options.go @@ -13,6 +13,7 @@ type options struct { router types.HttpRouter writer types.HttpWriter permissionChecker types.PermissionChecker + valueLookup types.ValueLookupFunc formatter *Formatter resourceDirectory string } @@ -30,6 +31,7 @@ func (o *options) Clone() *options { permissionChecker: o.permissionChecker, formatter: o.formatter, resourceDirectory: o.resourceDirectory, + valueLookup: o.valueLookup, } } @@ -47,6 +49,12 @@ func WithUriPrefix(s string) Option { } } +func WithValueLookup(f types.ValueLookupFunc) Option { + return func(o *options) { + o.valueLookup = f + } +} + // WithModuleName 模块名称 func WithModuleName(s string) Option { return func(o *options) { diff --git a/rest.go b/rest.go index 41cd2d2..8d536f6 100644 --- a/rest.go +++ b/rest.go @@ -516,6 +516,9 @@ func AutoMigrate(ctx context.Context, model any, cbs ...Option) (modelValue *Mod if scenarioModel, ok := model.(types.ScenarioModel); ok { modelValue.scenarios = scenarioModel.Scenario() } + if opts.valueLookup != nil { + modelValue.valueLookup = opts.valueLookup + } modelValue.hookMgr = hookMgr modelValue.schemaLookup = VisibleSchemas modelValue.permissionChecker = opts.permissionChecker