api

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetKeyCommonHandler

func GetKeyCommonHandler(ns ...string) string

GetKeyCommonHandler 获取 CommonHandler 注册到全局管理器的实例key

func GetKeyExampleHandler

func GetKeyExampleHandler(ns ...string) string

GetKeyExampleHandler 定义和获取 ExampleHandler 注册到全局管理器的实例key

func RegisterRouteHandlers

func RegisterRouteHandlers(ctx fiberhouse.IApplicationContext, app gin.IRouter)

Types

type CommonHandler

type CommonHandler struct {
	fiberhouse.ApiLocator        // 继承fiberhouse.ApiLocator
	KeyTestService        string // 定义依赖组件的全局管理器的实例key。通过key即可由 h.GetInstance(key) 方法获取实例,或由 fiberhouse.GetMustInstance[T](key) 泛型方法获取实例,无需wire或其他依赖注入工具
}

CommonHandler 示例公共处理器,继承自 fiberhouse.ApiLocator,具备获取上下文、配置、日志、注册实例等功能

func NewCommonHandler

func NewCommonHandler(ctx fiberhouse.IApplicationContext) *CommonHandler

NewCommonHandler 直接New,无需依赖注入(Wire) TestService对象,内部依赖走全局管理器延迟获取依赖组件

func (*CommonHandler) TestGetInstance

func (h *CommonHandler) TestGetInstance(c *gin.Context)

TestGetInstance 测试获取注册实例,通过 h.GetInstance(key) 方法获取TestService注册实例,无需编译阶段的wire依赖注入

func (*CommonHandler) TestGetMustInstance

func (h *CommonHandler) TestGetMustInstance(c *gin.Context)

TestGetMustInstance 测试获取注册实例,通过 fiberhouse.GetMustInstance[T](key) 泛型方法获取注册实例,无需编译阶段的wire依赖注入

func (*CommonHandler) TestGetMustInstanceFailed

func (h *CommonHandler) TestGetMustInstanceFailed(c *gin.Context)

TestGetMustInstanceFailed 测试获取注册实例失败,通过 fiberhouse.GetMustInstance[T](key) 泛型方法获取注册实例,无需编译阶段的wire依赖注入

type ExampleHandler

type ExampleHandler struct {
	fiberhouse.ApiLocator
	Service        *service.ExampleService // 直接定义依赖的组件指针类型成员变量,由wire注入,无需注册到全局管理器
	KeyTestService string                  // 定义依赖组件的全局管理器的实例key。通过key即可由 h.GetInstance(key) 方法获取实例,或由 fiberhouse.GetMustInstance[T](key) 泛型方法获取实例,无需wire或其他依赖注入工具
}

ExampleHandler 示例处理器,继承自 fiberhouse.ApiLocator,具备获取上下文、配置、日志、注册实例等功能

func (*ExampleHandler) CreateExample

func (h *ExampleHandler) CreateExample(c *gin.Context)

CreateExample godoc

@Summary		create A Example
@Description	create a new Example Object
@Tags			example
@Accept			json
@Produce		json
@Param			example	body		requestvo.ExampleReqVo	true	"Example Request"
@Success		200		{object}	response.RespInfo
@Failure		400		{object}	response.RespInfo
@Failure		422		{object}	response.RespInfo
@Failure		500		{object}	response.RespInfo
@Router			/create [post]

func (*ExampleHandler) GetExample

func (h *ExampleHandler) GetExample(c *gin.Context)

GetExample godoc

@Summary		get A Example
@Description	get Example Object by ID
@Tags			example
@Accept			json
@Produce		json
@Param			id	path		string	true	"Example ID"
@Success		200	{object}	response.RespInfo
@Failure		400	{object}	response.RespInfo
@Failure		404	{object}	response.RespInfo
@Failure		500	{object}	response.RespInfo
@Router			/example/get/{id} [get]

func (*ExampleHandler) GetExampleWithTaskDispatcher

func (h *ExampleHandler) GetExampleWithTaskDispatcher(c *gin.Context)

GetExampleWithTaskDispatcher godoc

@Summary		get A Example with Dispatcher Task
@Description	get Example Object by ID, on Dispatcher a task to do something
@Tags			example
@Accept			json
@Produce		json
@Param			id	path		string	true	"Example ID"
@Success		200	{object}	response.RespInfo
@Failure		400	{object}	response.RespInfo
@Failure		404	{object}	response.RespInfo
@Failure		500	{object}	response.RespInfo
@Router			/example/on-async-task/get/{id} [get]

func (*ExampleHandler) GetExamples

func (h *ExampleHandler) GetExamples(c *gin.Context)

GetExamples godoc

@Summary		get Examples with pagination
@Description	get paginated list of Example objects
@Tags			example
@Accept			json
@Produce		json
@Param			p	query		int	false	"Page number"	default(1)	minimum(1)
@Param			s	query		int	false	"Page size"		default(10)	minimum(1)	maximum(20)
@Success		200	{object}	response.RespInfo
@Failure		400	{object}	response.RespInfo
@Failure		422	{object}	response.RespInfo
@Failure		500	{object}	response.RespInfo
@Router			/list [get]

func (*ExampleHandler) HelloWorld

func (h *ExampleHandler) HelloWorld(c *gin.Context)

HelloWorld 测试接口,通过 h.GetInstance(key) 方法获取TestService注册实例,无需编译阶段的wire依赖注入

Jump to

Keyboard shortcuts

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