respx

package
v0.0.0-...-10b6da0 Latest Latest
Warning

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

Go to latest
Published: May 5, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Success        = 200
	ParamError     = 400
	Unauthorized   = 401
	Forbidden      = 403
	NotFound       = 404
	RateLimit      = 429
	ServerError    = 500
	GatewayTimeout = 504
)

业务错误码

Variables

This section is empty.

Functions

func Cleanup

func Cleanup() rest.Middleware

Cleanup 中间件:请求结束自动清理

func ErrHandler

func ErrHandler(ctx context.Context, err error) (int, any)

全局错误处理(自动识别所有错误)

func GetSuccessMsg

func GetSuccessMsg(ctx context.Context) string

GetSuccessMsg 获取当前请求的成功消息

func OkHandler

func OkHandler(ctx context.Context, data interface{}) any

OkHandler 成功包装

func Register

func Register()

Register 注册全局处理器

func RequestIDMiddleware

func RequestIDMiddleware() rest.Middleware

RequestIDMiddleware 生成并注入 Request ID

func SetSuccessMsg

func SetSuccessMsg(ctx context.Context, msg string)

SetSuccessMsg 存储当前请求的成功消息

Types

type Response

type Response struct {
	Code    int         `json:"code"`    // 业务码
	Message string      `json:"message"` // 提示信息
	Data    interface{} `json:"data"`    // 数据
}

func Fail

func Fail(code int, message string) *Response

Fail 失败返回

func Ok

func Ok(ctx context.Context, data interface{}) *Response

Ok 成功返回

Jump to

Keyboard shortcuts

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