mqtt_binding

package
v1.5.10 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2025 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: 执行绑定的参数 - responseIdentifier: 全局响应标识符 - middlewares: 该绑定的中间件

Types

type BindItem

type BindItem[O any] struct {
	// 相对主题
	Topic string

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

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

	// 获取响应标识符的函数
	ResponseIdentifierFunc ResponseIdentifierFunc

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

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

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

BindItem 通用BindItem

type Binder

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

func NewBinder

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

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

type FormDomainObjectsFunc

type FormDomainObjectsFunc func(c *mqtt_api.Context, params any) ([]domain.Object, error)

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

type Middleware

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

Middleware binder使用的中间件

type ResponseIdentifierFunc

type ResponseIdentifierFunc func(c *mqtt_api.Context, params any) (string, error)

ResponseIdentifierFunc 获取响应标识符的函数 参数: - c: 上下文 - params: 请求参数 - objects: 基于请求参数构造出的领域对象 - i: 基础设施 返回值: - 响应标识符 - 错误

type ServiceFunc

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

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

Jump to

Keyboard shortcuts

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