binding

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: May 31, 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 ...api.Handler)

func DeleteBind

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

func GetBind

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

func PostBind

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

func PutBind

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

func Static

func Static(binder *Binder, item *StaticBindItem)

func StaticFile

func StaticFile(binder *Binder, item *StaticFileBindItem)

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

type FormDomainObjectsFunc

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

type ServiceFunc

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

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 {
	RelativePath string
	Root         string
	WithBasePath bool
}

StaticBindItem 静态路由item

type StaticFileBindItem

type StaticFileBindItem struct {
	RelativePath string
	FilePath     string
	WithBasePath bool
}

Jump to

Keyboard shortcuts

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