resp

package
v0.33.5 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BadRequest

func BadRequest(c *app.RequestContext, message string)

func Error

func Error(c *app.RequestContext, code int)

Error 旧版 errors 码的错误响应(兼容老调用方)

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

func HTTPStatusForCode(code int) int

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 等)写成 业务错误响应;未实现该接口的错误按内部错误处理。

pkgerrors.New/Wrap 构造的业务错误(AppError = oekit BizError)**没有** ErrCode() 方法——若不单独提取,它们会全部塌成 10008「内部错误」: 形状非法这类**客户端**错误被报成服务端故障,调用方无从区分传参与 服务端坏了(2026-11-02 core#30 S27 冒烟实测暴露:wrapped_key 形状 校验的 10001 到 wire 上成了 10008)。⇒ 这里按 BizCode 透传。

func NotFound

func NotFound(c *app.RequestContext, message string)

func Page

func Page(c *app.RequestContext, list interface{}, total int64, page, pageSize int)

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

func ValidTraceID(tid string) bool

ValidTraceID 客户端自带 trace_id 白名单校验:非空、长度 ≤64、 字符集 [A-Za-z0-9._-]。原样采信任意值会把超长串回显进响应头并落入 访问日志(日志刷量/注入面),不合规一律重新生成。 供 pkg/middleware.RequestID 与本包 getOrGenTraceID 共用。

Types

type PageData

type PageData struct {
	List     interface{} `json:"list"`
	Total    int64       `json:"total"`
	Page     int         `json:"page"`
	PageSize int         `json:"page_size"`
}

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, 用于排错)
}

Jump to

Keyboard shortcuts

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