response

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BadRequestError added in v1.3.2

func BadRequestError(c *gin.Context, message string)

BadRequestError 错误请求

func BusinessError

func BusinessError(c *gin.Context, err error)

BusinessError 业务错误

func Error added in v1.3.2

func Error(c *gin.Context, err error)

Error 通用错误响应(自动追溯调用位置)

func ForbiddenError

func ForbiddenError(c *gin.Context, err error)

ForbiddenError 禁止访问

func MethodNotAllowedError

func MethodNotAllowedError(c *gin.Context, err error)

MethodNotAllowedError 方法不允许

func NotFoundError

func NotFoundError(c *gin.Context, err error)

NotFoundError 未找到

func PanicError added in v1.3.2

func PanicError(c *gin.Context, err any)

PanicError Panic 错误响应(用于 recovery 中间件)

func ServerError

func ServerError(c *gin.Context, err error)

ServerError 服务器内部错误

func Success

func Success(c *gin.Context, data any)

Success 成功响应

func SuccessWithMessage added in v1.3.2

func SuccessWithMessage(c *gin.Context, message string, data any)

SuccessWithMessage 成功响应(自定义消息)

func TooManyRequestsError added in v1.3.2

func TooManyRequestsError(c *gin.Context, err error)

TooManyRequestsError 请求过多

func UnauthorizedError

func UnauthorizedError(c *gin.Context)

UnauthorizedError 未授权

func ValidationError

func ValidationError(c *gin.Context, err error)

ValidationError 参数验证错误

Types

type Response

type Response struct {
	Code      int    `json:"code"`                     // 业务状态码
	Message   string `json:"message"`                  // 响应消息
	Data      any    `json:"data,omitempty"`           // 响应数据
	ErrorPath string `json:"error_path,omitempty"`     // 错误路径(仅开发环境)
	Function  string `json:"error_function,omitempty"` // 错误函数(仅开发环境)
	Extra     any    `json:"extra,omitempty"`          // 额外信息
}

Response 统一响应结构

type StackFrame added in v1.3.2

type StackFrame struct {
	Function string `json:"function"`  // 函数名
	File     string `json:"file"`      // 文件名
	Line     int    `json:"line"`      // 行号
	FullPath string `json:"full_path"` // 完整路径
}

StackFrame 堆栈帧结构(用于 panic 错误追踪)

Jump to

Keyboard shortcuts

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