feat: 增加注册注入参数的方法

This commit is contained in:
2025-10-30 15:48:43 +08:00
parent 1a9bc7b6dd
commit 028d16ac5a
3 changed files with 44 additions and 14 deletions

25
router/common_param.go Normal file
View File

@ -0,0 +1,25 @@
// Package router ...
//
// Description : router ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2025-10-30 15:39
package router
import "github.com/gin-gonic/gin"
// GetCommonParam 获取公共参数
type GetCommonParam func(ctx *gin.Context) (any, error)
// AddCommonParamRule 添加公共参数注入规则
func (s *server) AddCommonParamRule(fieldName string, getParamFunc GetCommonParam) {
s.commonParam[fieldName] = getParamFunc
}
// AddCommonParamRules 批量添加公共参数注入规则
func (s *server) AddCommonParamRules(rules map[string]GetCommonParam) {
for fieldName, rule := range rules {
s.AddCommonParamRule(fieldName, rule)
}
}