feat: 增加注册注入参数的方法
This commit is contained in:
25
router/common_param.go
Normal file
25
router/common_param.go
Normal 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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user