response

package
v0.0.0-...-7c473ab Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2025 License: MIT Imports: 0 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// 成功
	CodeSuccess = 0

	// 客户端错误(4xx)
	CodeBadRequest       = 400
	CodeUnauthorized     = 401
	CodeForbidden        = 403
	CodeNotFound         = 404
	CodeMethodNotAllowed = 405
	CodeRequestTimeout   = 408
	CodeConflict         = 409
	CodeTooManyRequests  = 429

	// 服务端错误(5xx)
	CodeInternalServerError = 500
	CodeNotImplemented      = 501
	CodeBadGateway          = 502
	CodeServiceUnavailable  = 503
	CodeGatewayTimeout      = 504
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Response

type Response[T any] struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
	Data    T      `json:"data"`
}

ResponseWithData 用来在Swagger里指定Data的具体类型

func BadGateway

func BadGateway(msg ...string) Response[any]

func BadRequest

func BadRequest(msg ...string) Response[any]

func Conflict

func Conflict(msg ...string) Response[any]

func Fail

func Fail(code int, message string) Response[any]

Fail 返回失败

func Forbidden

func Forbidden(msg ...string) Response[any]

func GatewayTimeout

func GatewayTimeout(msg ...string) Response[any]

func InternalServerError

func InternalServerError(msg ...string) Response[any]

func MethodNotAllowed

func MethodNotAllowed(msg ...string) Response[any]

func NotFound

func NotFound(msg ...string) Response[any]

func NotImplemented

func NotImplemented(msg ...string) Response[any]

func RequestTimeout

func RequestTimeout(msg ...string) Response[any]

func ServiceUnavailable

func ServiceUnavailable(msg ...string) Response[any]

func Success

func Success[T any](data T) Response[T]

Success 返回成功

func TooManyRequests

func TooManyRequests(msg ...string) Response[any]

func Unauthorized

func Unauthorized(msg ...string) Response[any]

Jump to

Keyboard shortcuts

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