Documentation
¶
Overview ¶
Package errorsx 提供 errors 包与 httpserver typed handler 之间的桥接映射。
适用场景:
- 团队统一使用 github.com/tsopia/go-kit/errors 作为业务错误出口
- 需要把错误码、错误名和 HTTP 状态稳定映射到 typed handler 响应
- 不希望 httpserver core 直接依赖 errors 包
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Mapper ¶
func Mapper() httpserver.ErrorMapper
Mapper 返回可直接挂到 typed handler 的 errors 到 HTTP 响应映射器。
Types ¶
type ResponseBody ¶
type ResponseBody struct {
Code int `json:"code"`
Name string `json:"name"`
Message string `json:"message"`
Details map[string]any `json:"details,omitempty"`
}
ResponseBody 描述 errors 包桥接到 HTTP 响应时使用的默认结构。
func Response ¶
func Response(err error) (int, ResponseBody)
Response 将 errors 包的业务错误映射为 HTTP 状态码和响应体。
Click to show internal directories.
Click to hide internal directories.