Help us shape the future of Go! Take the 2026 Go Developer Survey

response

package
v1.38.0 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: MIT 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)

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 NoContent

func NoContent(c *app.RequestContext)

NoContent sends a 204 No Content response

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 分页数据

type Pagination

type Pagination struct {
	Page       int   `json:"page"`
	PageSize   int   `json:"page_size"`
	Total      int64 `json:"total"`
	TotalPages int   `json:"total_pages"`
}

Pagination 分页信息

type Response

type Response struct {
	Code      int         `json:"code"`
	Message   string      `json:"message"`
	Data      interface{} `json:"data"`
	Timestamp int64       `json:"timestamp"`
}

Response 统一响应格式

Jump to

Keyboard shortcuts

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