binding

package
v0.11.37 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 4, 2024 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bind

func Bind[O any](binder *Binder, item *BindItem[O], middlewares ...Middleware)

Bind 通用绑定 类型参数: - O: 响应数据类型,对应response.SendResponseFunc的data的类型 参数: - binder: 用来执行绑定的binder - item: 执行绑定的参数 - middlewares: 该绑定的中间件

func DeleteBind

func DeleteBind[O any](binder *Binder, item *SimpleBindItem[O], middlewares ...Middleware)

DeleteBind 进行DELETE绑定,创建DELETE API并完成接口逻辑编写 类型参数: - O: 响应数据类型,对应response.SendResponseFunc的data的类型 参数: - binder: 用来执行绑定的binder - item: 执行绑定的参数 - middlewares: 该绑定的中间件

func GetBind

func GetBind[O any](binder *Binder, item *SimpleBindItem[O], middlewares ...Middleware)

GetBind 进行GET绑定,创建GET API并完成接口逻辑编写 类型参数: - O: 响应数据类型,对应response.SendResponseFunc的data的类型 参数: - binder: 用来执行绑定的binder - item: 执行绑定的参数 - middlewares: 该绑定的中间件 返回值: 无

func PostBind

func PostBind[O any](binder *Binder, item *SimpleBindItem[O], middlewares ...Middleware)

PostBind 进行POST绑定,创建POST API并完成接口逻辑编写 类型参数: - O: 响应数据类型,对应response.SendResponseFunc的data的类型 参数: - binder: 用来执行绑定的binder - item: 执行绑定的参数 - middlewares: 该绑定的中间件

func PutBind

func PutBind[O any](binder *Binder, item *SimpleBindItem[O], middlewares ...Middleware)

PutBind 进行PUT绑定,创建PUT API并完成接口逻辑编写 类型参数: - O: 响应数据类型,对应response.SendResponseFunc的data的类型 参数: - binder: 用来执行绑定的binder - item: 执行绑定的参数 - middlewares: 该绑定的中间件 返回值: 无

func Static

func Static(binder *Binder, item *StaticBindItem)

Static 静态绑定 参数: - binder: 用来执行绑定的binder - item: 执行绑定的参数

func StaticFile

func StaticFile(binder *Binder, item *StaticFileBindItem)

StaticFile 静态文件绑定 参数: - binder: 用来执行绑定的binder - item: 执行绑定的参数

Types

type BindItem

type BindItem[O any] struct {
	Method string
	*SimpleBindItem[O]
}

BindItem 通用BindItem

type Binder

type Binder struct {
	// contains filtered or unexported fields
}

func NewBinder

func NewBinder(router api.Router, i *infrastructure.Infrastructure) *Binder

NewBinder 构造Binder 参数: - router: 使用的路由 - i: 使用的基础设施 返回值: - 构造的binder

type FormDomainObjectsFunc

type FormDomainObjectsFunc func(c *api.Context, params request.Params) ([]domain.Object, error)

FormDomainObjectsFunc 构造领域对象函数类型 参数: - c: 上下文 - params: 请求参数 返回值: - 基于请求参数构造的领域对象,回传到ServiceFunc的objects参数 - 错误

type Middleware added in v0.8.0

type Middleware func(c *api.Context, i *infrastructure.Infrastructure)

Middleware binder使用的中间件

type ServiceFunc

type ServiceFunc[O any] func(c *api.Context, params request.Params, objects []domain.Object, i *infrastructure.Infrastructure) (O, error)

ServiceFunc 服务函数(业务逻辑函数) 类型参数: - O: 响应数据类型,对应response.SendResponseFunc的data的类型 参数: - c: 上下文 - params: 请求参数 - objects: 基于请求参数构造出的领域对象 - i: 基础设施 返回值: - 响应数据 - 错误

type SimpleBindItem

type SimpleBindItem[O any] struct {
	// URL相对路径
	Path string

	// 响应泛型函数,如果不响应,需要使用NoResponse零值占位
	SendResponseFunc response.SendResponseFunc[O]

	// 使用的请求参数,非必传,当请求参数为nil时,说明该接口没有参数
	RequestParams request.Params

	// 可选的请求参数绑定函数
	// 非必传,POST和PUT请求默认为JsonBody,DELETE和GET默认为QueryParams
	// 额外还提供了一些转化函数:
	// BindPathParams: 绑定路径参数
	// BindMultipartForm: 绑定multipart form
	// BindFormBody: 绑定form body
	// XMLBody: 绑定XML body
	BindRequestParamsFunc request.BindRequestParamsFunc

	// 通过请求参数构造使用的领域对象,之后在ServiceFunc中会按照构造实体的顺序进行回调
	// 非必传,如果该字段为nil,则说明没有领域对象
	// 与Objects字段二选一使用,如果都指定,会按照该字段处理
	FormDomainObjectsFunc FormDomainObjectsFunc

	// 使用的领域对象,当使用Tag对实体进行标注后,可以直接通过该字段给定实体,之后在ServiceFunc中会按照给定实体的顺序进行回调
	// 非必传,如果为nil或长度为0,则说明没有领域对象
	// 与FormObjectsFunc字段二选一使用,如果都指定,会按照FormObjectsFunc字段处理
	Objects []domain.Object

	// 应用服务泛型函数
	ServiceFunc ServiceFunc[O]
}

SimpleBindItem 简化的BindItem

type StaticBindItem

type StaticBindItem struct {
	// 创建的静态绑定API的URL相对路径
	RelativePath string

	// 目录的根路径
	Root string

	// 传递的RelativePath是否包含了路由的BasePath
	WithBasePath bool
}

StaticBindItem 静态BindItem

type StaticFileBindItem

type StaticFileBindItem struct {
	// 创建的静态绑定API的URL相对路径
	RelativePath string

	// 文件路径
	FilePath string

	// 传递的RelativePath是否包含了路由的BasePath
	WithBasePath bool
}

StaticFileBindItem 静态文件BindItem

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL