فهرست منبع

完成binding文档

yjp 10 ماه پیش
والد
کامیت
efc0512fa8

+ 7 - 0
framework/binding/bind_item.go

@@ -12,6 +12,13 @@ import (
 	"strings"
 )
 
+// Bind 通用绑定
+// 类型参数:
+// - O: 响应数据类型,对应response.SendResponseFunc的data的类型
+// 参数:
+// - binder: 用来执行绑定的binder
+// - item: 执行绑定的参数
+// - middlewares: 该绑定的中间件
 func Bind[O any](binder *Binder, item *BindItem[O], middlewares ...Middleware) {
 	item.bind(binder, middlewares...)
 }

+ 6 - 0
framework/binding/binder.go

@@ -10,6 +10,12 @@ type Binder struct {
 	i      *infrastructure.Infrastructure
 }
 
+// NewBinder 构造Binder
+// 参数:
+// - router: 使用的路由
+// - i: 使用的基础设施
+// 返回值:
+// - 构造的binder
 func NewBinder(router api.Router, i *infrastructure.Infrastructure) *Binder {
 	return &Binder{
 		router: router,

+ 1 - 0
framework/binding/middleware.go

@@ -5,4 +5,5 @@ import (
 	"git.sxidc.com/go-framework/baize/framework/core/infrastructure"
 )
 
+// Middleware binder使用的中间件
 type Middleware func(c *api.Context, i *infrastructure.Infrastructure)

+ 50 - 1
framework/binding/simple_bind_item.go

@@ -9,23 +9,72 @@ import (
 	"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) {
 	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) {
 	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) {
 	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) {
 	item.bind(binder, http.MethodGet, middlewares...)
 }
 
+// FormDomainObjectsFunc 构造领域对象函数类型
+// 参数:
+// - c: 上下文
+// - params: 请求参数
+// 返回值:
+// - 基于请求参数构造的领域对象,回传到ServiceFunc的objects参数
+// - 错误
 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)
 
 // SimpleBindItem 简化的BindItem
@@ -49,7 +98,7 @@ type SimpleBindItem[O any] struct {
 	BindRequestParamsFunc request.BindRequestParamsFunc
 
 	// 通过请求参数构造使用的领域对象,之后在ServiceFunc中会按照构造实体的顺序进行回调
-	// 非必传,如果为nil,则说明没有领域对象
+	// 非必传,如果该字段为nil,则说明没有领域对象
 	// 与Objects字段二选一使用,如果都指定,会按照该字段处理
 	FormDomainObjectsFunc FormDomainObjectsFunc
 

+ 22 - 3
framework/binding/static.go

@@ -2,18 +2,31 @@ package binding
 
 import "strings"
 
+// Static 静态绑定
+// 参数:
+// - binder: 用来执行绑定的binder
+// - item: 执行绑定的参数
 func Static(binder *Binder, item *StaticBindItem) {
 	item.bind(binder)
 }
 
+// StaticFile 静态文件绑定
+// 参数:
+// - binder: 用来执行绑定的binder
+// - item: 执行绑定的参数
 func StaticFile(binder *Binder, item *StaticFileBindItem) {
 	item.bind(binder)
 }
 
-// StaticBindItem 静态路由item
+// StaticBindItem 静态BindItem
 type StaticBindItem struct {
+	// 创建的静态绑定API的URL相对路径
 	RelativePath string
-	Root         string
+
+	// 目录的根路径
+	Root string
+
+	// 传递的RelativePath是否包含了路由的BasePath
 	WithBasePath bool
 }
 
@@ -25,9 +38,15 @@ func (item *StaticBindItem) bind(binder *Binder) {
 	}
 }
 
+// StaticFileBindItem 静态文件BindItem
 type StaticFileBindItem struct {
+	// 创建的静态绑定API的URL相对路径
 	RelativePath string
-	FilePath     string
+
+	// 文件路径
+	FilePath string
+
+	// 传递的RelativePath是否包含了路由的BasePath
 	WithBasePath bool
 }