callback

package
v1.0.4 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	CodeSuccess       = Code{HTTP: http.StatusOK, Biz: 0}
	CodeBadRequest    = Code{HTTP: http.StatusBadRequest, Biz: 400}
	CodeNotFound      = Code{HTTP: http.StatusNotFound, Biz: 404}
	CodeFileTooLarge  = Code{HTTP: http.StatusRequestEntityTooLarge, Biz: 413}
	CodeInternalError = Code{HTTP: http.StatusInternalServerError, Biz: 500}
)

Functions

func Error

func Error(ctx *gin.Context, code Code, msg string)

Error sends an HTTP error response and aborts the handler chain.

func HandleError

func HandleError(ctx *gin.Context, err error)

HandleError checks if err is a BizError and writes the appropriate response. For unknown errors it falls back to 500.

func Success

func Success(ctx *gin.Context, data interface{})

Success sends a 200 response with code 0.

Types

type BizError

type BizError struct {
	// contains filtered or unexported fields
}

BizError is an error that carries a Code for direct API response.

func NewBizError

func NewBizError(code Code, msg string) *BizError

func (*BizError) Error

func (e *BizError) Error() string

type Code

type Code struct {
	HTTP int
	Biz  int
}

Code bundles a business error code with its corresponding HTTP status.

type Response

type Response struct {
	Code int         `json:"code"`
	Msg  string      `json:"msg"`
	Data interface{} `json:"data,omitempty"`
}

Response is the unified API response format.

Jump to

Keyboard shortcuts

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