From d70c3a0ceea92e18d1f98f137a51f18cd20d4f38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Sun, 17 Aug 2025 21:50:59 +0800 Subject: [PATCH] =?UTF-8?q?upgrade:=20=E4=BC=98=E5=8C=96=20WithInitContext?= =?UTF-8?q?Data=20=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- router/option.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/router/option.go b/router/option.go index 8975ade..57ba8a8 100644 --- a/router/option.go +++ b/router/option.go @@ -44,9 +44,13 @@ func WithDisableInitRequest(disable bool) SetServerOptionFunc { } // WithInitContextData 初始化一些请求数据 -func WithInitContextData(data map[string]any) SetServerOptionFunc { +func WithInitContextData(formatFunc func(ctx *gin.Context) map[string]any) SetServerOptionFunc { return func(so *serverOption) { + if nil == formatFunc { + return + } f := func(ctx *gin.Context) { + data := formatFunc(ctx) for k, v := range data { ctx.Set(k, v) }