Documentation
¶
Index ¶
- func BadRequest(c *app.RequestContext, message string)
- func Created(c *app.RequestContext, data interface{})
- func Error(c *app.RequestContext, statusCode int, message string)
- func FromError(c *app.RequestContext, err error)
- func InternalError(c *app.RequestContext, message string)
- func NoContent(c *app.RequestContext)
- func NotFound(c *app.RequestContext, message string)
- func Paginated(c *app.RequestContext, list interface{}, total int64, page, pageSize int)
- func Success(c *app.RequestContext, data interface{})
- type BatchResponse
- type PaginatedData
- type Pagination
- type Response
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BadRequest ¶
func BadRequest(c *app.RequestContext, message string)
BadRequest sends a 400 Bad Request response
func Created ¶
func Created(c *app.RequestContext, data interface{})
Created sends a 201 Created response
func Error ¶
func Error(c *app.RequestContext, statusCode int, message string)
Error sends an error response with a custom status code (kept for backward compatibility)
func FromError ¶ added in v1.21.0
func FromError(c *app.RequestContext, err error)
FromError 按 core 的错误分类契约(corebridge.Classify)选状态码并回响应。
- not_found → 404,回传业务消息(与既往 errors.Is(ErrNotFound) 分支一致)
- validation → 400
- conflict → 409(任务运行中/并发上限/合规冻结)
- auth → 401
- rate_limited → 429
- unavailable → 503,消息回传(平台侧 5xx,客户端可重试)
- internal/未分类 → 500,详情只进日志(沿用 InternalError 的安全策略)
func InternalError ¶
func InternalError(c *app.RequestContext, message string)
InternalError sends a 500 Internal Server Error response. 出于安全:原始 detail 只写入服务端日志,不回传客户端(避免泄露 SQL/DSN/表名/文件路径等内部信息)。
func NotFound ¶
func NotFound(c *app.RequestContext, message string)
NotFound sends a 404 Not Found response
func Paginated ¶
func Paginated(c *app.RequestContext, list interface{}, total int64, page, pageSize int)
Paginated sends a 200 OK response with pagination data
func Success ¶
func Success(c *app.RequestContext, data interface{})
Success sends a 200 OK response
Types ¶
type BatchResponse ¶
type BatchResponse struct {
Total int `json:"total"`
Success int `json:"success"`
Failed int `json:"failed"`
Errors []string `json:"errors,omitempty"`
}
BatchResponse 批量操作响应
type PaginatedData ¶
type PaginatedData struct {
List interface{} `json:"list"`
Pagination Pagination `json:"pagination"`
}
PaginatedData 分页数据
Click to show internal directories.
Click to hide internal directories.