|
@@ -9,23 +9,72 @@ import (
|
|
|
"net/http"
|
|
"net/http"
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
+// PostBind 进行POST绑定,创建POST API并完成接口逻辑编写
|
|
|
|
|
+// 类型参数:
|
|
|
|
|
+// - O: 响应数据类型,对应response.SendResponseFunc的data的类型
|
|
|
|
|
+// 参数:
|
|
|
|
|
+// - binder: 用来执行绑定的binder
|
|
|
|
|
+// - item: 执行绑定的参数
|
|
|
|
|
+// - middlewares: 该绑定的中间件
|
|
|
func PostBind[O any](binder *Binder, item *SimpleBindItem[O], middlewares ...Middleware) {
|
|
func PostBind[O any](binder *Binder, item *SimpleBindItem[O], middlewares ...Middleware) {
|
|
|
item.bind(binder, http.MethodPost, middlewares...)
|
|
item.bind(binder, http.MethodPost, middlewares...)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// DeleteBind 进行DELETE绑定,创建DELETE API并完成接口逻辑编写
|
|
|
|
|
+// 类型参数:
|
|
|
|
|
+// - O: 响应数据类型,对应response.SendResponseFunc的data的类型
|
|
|
|
|
+// 参数:
|
|
|
|
|
+// - binder: 用来执行绑定的binder
|
|
|
|
|
+// - item: 执行绑定的参数
|
|
|
|
|
+// - middlewares: 该绑定的中间件
|
|
|
func DeleteBind[O any](binder *Binder, item *SimpleBindItem[O], middlewares ...Middleware) {
|
|
func DeleteBind[O any](binder *Binder, item *SimpleBindItem[O], middlewares ...Middleware) {
|
|
|
item.bind(binder, http.MethodDelete, middlewares...)
|
|
item.bind(binder, http.MethodDelete, middlewares...)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// PutBind 进行PUT绑定,创建PUT API并完成接口逻辑编写
|
|
|
|
|
+// 类型参数:
|
|
|
|
|
+// - O: 响应数据类型,对应response.SendResponseFunc的data的类型
|
|
|
|
|
+// 参数:
|
|
|
|
|
+// - binder: 用来执行绑定的binder
|
|
|
|
|
+// - item: 执行绑定的参数
|
|
|
|
|
+// - middlewares: 该绑定的中间件
|
|
|
|
|
+// 返回值: 无
|
|
|
func PutBind[O any](binder *Binder, item *SimpleBindItem[O], middlewares ...Middleware) {
|
|
func PutBind[O any](binder *Binder, item *SimpleBindItem[O], middlewares ...Middleware) {
|
|
|
item.bind(binder, http.MethodPut, middlewares...)
|
|
item.bind(binder, http.MethodPut, middlewares...)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// GetBind 进行GET绑定,创建GET API并完成接口逻辑编写
|
|
|
|
|
+// 类型参数:
|
|
|
|
|
+// - O: 响应数据类型,对应response.SendResponseFunc的data的类型
|
|
|
|
|
+// 参数:
|
|
|
|
|
+// - binder: 用来执行绑定的binder
|
|
|
|
|
+// - item: 执行绑定的参数
|
|
|
|
|
+// - middlewares: 该绑定的中间件
|
|
|
|
|
+// 返回值: 无
|
|
|
func GetBind[O any](binder *Binder, item *SimpleBindItem[O], middlewares ...Middleware) {
|
|
func GetBind[O any](binder *Binder, item *SimpleBindItem[O], middlewares ...Middleware) {
|
|
|
item.bind(binder, http.MethodGet, middlewares...)
|
|
item.bind(binder, http.MethodGet, middlewares...)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// FormDomainObjectsFunc 构造领域对象函数类型
|
|
|
|
|
+// 参数:
|
|
|
|
|
+// - c: 上下文
|
|
|
|
|
+// - params: 请求参数
|
|
|
|
|
+// 返回值:
|
|
|
|
|
+// - 基于请求参数构造的领域对象,回传到ServiceFunc的objects参数
|
|
|
|
|
+// - 错误
|
|
|
type FormDomainObjectsFunc func(c *api.Context, params request.Params) ([]domain.Object, error)
|
|
type FormDomainObjectsFunc func(c *api.Context, params request.Params) ([]domain.Object, error)
|
|
|
|
|
+
|
|
|
|
|
+// ServiceFunc 服务函数(业务逻辑函数)
|
|
|
|
|
+// 类型参数:
|
|
|
|
|
+// - O: 响应数据类型,对应response.SendResponseFunc的data的类型
|
|
|
|
|
+// 参数:
|
|
|
|
|
+// - c: 上下文
|
|
|
|
|
+// - params: 请求参数
|
|
|
|
|
+// - objects: 基于请求参数构造出的领域对象
|
|
|
|
|
+// - i: 基础设施
|
|
|
|
|
+// 返回值:
|
|
|
|
|
+// - 响应数据
|
|
|
|
|
+// - 错误
|
|
|
type ServiceFunc[O any] func(c *api.Context, params request.Params, objects []domain.Object, i *infrastructure.Infrastructure) (O, error)
|
|
type ServiceFunc[O any] func(c *api.Context, params request.Params, objects []domain.Object, i *infrastructure.Infrastructure) (O, error)
|
|
|
|
|
|
|
|
// SimpleBindItem 简化的BindItem
|
|
// SimpleBindItem 简化的BindItem
|
|
@@ -49,7 +98,7 @@ type SimpleBindItem[O any] struct {
|
|
|
BindRequestParamsFunc request.BindRequestParamsFunc
|
|
BindRequestParamsFunc request.BindRequestParamsFunc
|
|
|
|
|
|
|
|
// 通过请求参数构造使用的领域对象,之后在ServiceFunc中会按照构造实体的顺序进行回调
|
|
// 通过请求参数构造使用的领域对象,之后在ServiceFunc中会按照构造实体的顺序进行回调
|
|
|
- // 非必传,如果为nil,则说明没有领域对象
|
|
|
|
|
|
|
+ // 非必传,如果该字段为nil,则说明没有领域对象
|
|
|
// 与Objects字段二选一使用,如果都指定,会按照该字段处理
|
|
// 与Objects字段二选一使用,如果都指定,会按照该字段处理
|
|
|
FormDomainObjectsFunc FormDomainObjectsFunc
|
|
FormDomainObjectsFunc FormDomainObjectsFunc
|
|
|
|
|
|