|
|
@@ -43,7 +43,7 @@ func NewBinding(apiVersion string, middlewares ...middleware.Func) *Binding {
|
|
|
|
|
|
type HandleFunc func(c *binding_context.Context)
|
|
|
|
|
|
-func (binding *Binding) AddHandler(method string, relativePath string, handleFunc HandleFunc) error {
|
|
|
+func (binding *Binding) AddHandler(method string, relativePath string, handleFunctions []HandleFunc) error {
|
|
|
if utils.IsStringEmpty(method) {
|
|
|
return errors.New("没有传递方法名")
|
|
|
}
|
|
|
@@ -52,13 +52,20 @@ func (binding *Binding) AddHandler(method string, relativePath string, handleFun
|
|
|
return errors.New("没有传递相对路径")
|
|
|
}
|
|
|
|
|
|
- if handleFunc == nil {
|
|
|
+ if handleFunctions == nil || len(handleFunctions) == 0 {
|
|
|
return errors.New("没有传递处理函数")
|
|
|
}
|
|
|
|
|
|
- binding.routerGroup.Handle(method, relativePath, func(c *gin.Context) {
|
|
|
- handleFunc(&binding_context.Context{Context: c})
|
|
|
- })
|
|
|
+ // 给单个路由增加中间件
|
|
|
+ ginHandleFunctions := make([]gin.HandlerFunc, 0)
|
|
|
+ for _, handleFunction := range handleFunctions {
|
|
|
+ innerFunction := handleFunction
|
|
|
+ ginHandleFunctions = append(ginHandleFunctions, func(c *gin.Context) {
|
|
|
+ innerFunction(&binding_context.Context{Context: c})
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ binding.routerGroup.Handle(method, relativePath, ginHandleFunctions...)
|
|
|
|
|
|
return nil
|
|
|
}
|