|
|
@@ -1,6 +1,7 @@
|
|
|
package http_binding
|
|
|
|
|
|
import (
|
|
|
+ "errors"
|
|
|
"git.sxidc.com/go-tools/api_binding/http_binding/binding_context"
|
|
|
"git.sxidc.com/go-tools/api_binding/http_binding/middleware"
|
|
|
"git.sxidc.com/go-tools/api_binding/http_binding/request"
|
|
|
@@ -40,8 +41,26 @@ func NewBinding(apiVersion string, middlewares ...middleware.Func) *Binding {
|
|
|
return &Binding{routerGroup: routerInstance.Group(apiPrefix, ginMiddlewares...)}
|
|
|
}
|
|
|
|
|
|
-func (binding *Binding) GetRouterGroup() *gin.RouterGroup {
|
|
|
- return binding.routerGroup
|
|
|
+type HandleFunc func(c *binding_context.Context)
|
|
|
+
|
|
|
+func (binding *Binding) AddHandler(method string, relativePath string, handleFunc HandleFunc) error {
|
|
|
+ if utils.IsStringEmpty(method) {
|
|
|
+ return errors.New("没有传递方法名")
|
|
|
+ }
|
|
|
+
|
|
|
+ if utils.IsStringEmpty(relativePath) {
|
|
|
+ return errors.New("没有传递相对路径")
|
|
|
+ }
|
|
|
+
|
|
|
+ if handleFunc == nil {
|
|
|
+ return errors.New("没有传递处理函数")
|
|
|
+ }
|
|
|
+
|
|
|
+ binding.routerGroup.Handle(method, relativePath, func(c *gin.Context) {
|
|
|
+ handleFunc(&binding_context.Context{Context: c})
|
|
|
+ })
|
|
|
+
|
|
|
+ return nil
|
|
|
}
|
|
|
|
|
|
func PostBind[I any, O any](b *Binding, item *SimpleBindItem[I, O], middlewares ...middleware.Func) {
|