From 01a671dff84cf5ac3895f84d60f9dc5ba3213bf5 Mon Sep 17 00:00:00 2001 From: Yavolte Date: Tue, 17 Jun 2025 18:27:09 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0valueLookup=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- options.go | 8 ++++++++ rest.go | 3 +++ 2 files changed, 11 insertions(+) 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