package
0.0.0-20241223072440-270bddf36b8b
Repository: https://github.com/yu1ec/go-pkg.git
Documentation: pkg.go.dev

# README

Respx

响应处理库,支持自定义响应码,响应信息,HTTP 状态码, 事件驱动

使用

事件驱动

func init() {
    respx.RegisterEvent(respx.BeforeResponse, func(w respx.ResponseWriter, data any) {
        // 在响应发送前执行一些操作,比如日志记录
        log.Printf("准备发送响应: %v", data)
    })

    respx.RegisterEvent(respx.AfterResponse, func(w respx.ResponseWriter, data any) {
        // 在响应发送后执行一些操作,比如性能监控
        log.Printf("响应已发送: %v", data)
    })
}

自定义响应码

# Functions

ClearEventHandlers 清除所有注册的事件处理器.
EventSource Server-Sent Events 的实现.
JsonContent 是 JSON 响应.
Pagination 是分页响应.
JsonResponseWithError 携带错误信息的Json响应.
NewResponseWriter 创建一个新的 ResponseWriter.
NoContent 是空响应.
PlainContent 是纯文本响应.
No description provided by the author
RegisterEvent 注册一个事件处理器.

# Constants

No description provided by the author
No description provided by the author

# Structs

No description provided by the author
GinResponseWriter 包装 gin.Context 以实现 ResponseWriter 接口.
No description provided by the author

# Interfaces

ResponseWriter 是一个接口,可以同时被 gin.Context 和 http.ResponseWriter 实现.

# Type aliases

No description provided by the author
No description provided by the author
No description provided by the author