Documentation
¶
Index ¶
- func BadRequest(c *app.RequestContext, message string)
- func Error(c *app.RequestContext, code int)
- func ErrorWithData(c *app.RequestContext, code int, message string, data interface{})
- func ErrorWithMessage(c *app.RequestContext, code int, message string)
- func HTTPStatusForCode(code int) int
- func InternalError(c *app.RequestContext, message string)
- func NewErrorByCode(c *app.RequestContext, code int)
- func NewErrorWithData(c *app.RequestContext, code int, message string, data interface{})
- func NewErrorWithMessage(c *app.RequestContext, code int, message string)
- func NewTypedError(c *app.RequestContext, err error)
- func NotFound(c *app.RequestContext, message string)
- func Page(c *app.RequestContext, list interface{}, total int64, page, pageSize int)
- func Success(c *app.RequestContext, data interface{})
- func SuccessWithMessage(c *app.RequestContext, message string, data interface{})
- func Unauthorized(c *app.RequestContext, message string)
- func ValidTraceID(tid string) bool
- type PageData
- type Response
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BadRequest ¶
func BadRequest(c *app.RequestContext, message string)
func ErrorWithData ¶
func ErrorWithData(c *app.RequestContext, code int, message string, data interface{})
func ErrorWithMessage ¶
func ErrorWithMessage(c *app.RequestContext, code int, message string)
func HTTPStatusForCode ¶ added in v0.32.7
HTTPStatusForCode 导出业务码 → HTTP 状态 的映射。
供取件闸门**契约守卫**(bootstrap/share_surface_contract_test.go)核对 「契约表登记的 HTTP 状态」与「运行时实际映射」是否一致 ⇒ 2026-10-25 审计 A9 指出的「契约表只登记业务码 ⇒ 状态码退化结构上无法被发现」由此闭合。
func InternalError ¶
func InternalError(c *app.RequestContext, message string)
func NewErrorByCode ¶
func NewErrorByCode(c *app.RequestContext, code int)
NewErrorByCode 新版业务码错误响应(推荐) 自动根据业务码选择 HTTP 状态:
401/403/404/429/500/503 等
func NewErrorWithData ¶
func NewErrorWithData(c *app.RequestContext, code int, message string, data interface{})
NewErrorWithData 新版业务码 + data
func NewErrorWithMessage ¶
func NewErrorWithMessage(c *app.RequestContext, code int, message string)
NewErrorWithMessage 新版业务码 + 自定义 message
func NewTypedError ¶
func NewTypedError(c *app.RequestContext, err error)
NewTypedError 把实现 ErrCode() int 的 typed error(gate/moderation 等)写成 业务错误响应;未实现该接口的错误按内部错误处理。
func NotFound ¶
func NotFound(c *app.RequestContext, message string)
func Success ¶
func Success(c *app.RequestContext, data interface{})
func SuccessWithMessage ¶
func SuccessWithMessage(c *app.RequestContext, message string, data interface{})
func Unauthorized ¶
func Unauthorized(c *app.RequestContext, message string)
func ValidTraceID ¶
ValidTraceID 客户端自带 trace_id 白名单校验:非空、长度 ≤64、 字符集 [A-Za-z0-9._-]。原样采信任意值会把超长串回显进响应头并落入 访问日志(日志刷量/注入面),不合规一律重新生成。 供 pkg/middleware.RequestID 与本包 getOrGenTraceID 共用。
Types ¶
type Response ¶
type Response struct {
Code int `json:"code"`
Message string `json:"message"`
Data interface{} `json:"data,omitempty"`
TraceID string `json:"trace_id,omitempty"`
}
Response 全站统一响应 envelope
{
"code": 业务码 (0=成功),
"message": 业务码默认文案 / 自定义 message,
"data": 业务数据 (omitempty),
"trace_id": 请求链路 ID (omitempty, 用于排错)
}
Click to show internal directories.
Click to hide internal directories.