response

package
v0.9.4 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ResponesFILE

func ResponesFILE(c *gin.Context, filename string)

func ResponseBytes

func ResponseBytes(c *gin.Context, responder Responder, data ...[]byte)

func ResponseBytesList

func ResponseBytesList(c *gin.Context, responder Responder, total int64, data ...[]byte)

func ResponseDATA

func ResponseDATA(c *gin.Context, data []byte, headers ...map[string]string)

func ResponseJSON

func ResponseJSON(c *gin.Context, responder Responder, data ...any)

func ResponseTEXT

func ResponseTEXT(c *gin.Context, responder Responder, data ...any)

Types

type Code

type Code int32
const (
	CodeSuccess Code = 0
	CodeFailure Code = -1
)

成功处理和失败处理状态码

const (
	CodeInvalidParam Code = 1000 + iota
	CodeBadRequest
	CodeInvalidToken
	CodeNeedLogin
	CodeUnauthorized
	CodeNetworkTimeout
	CodeContextTimeout
	CodeTooManyRequests
	CodeNotFound
	CodeForbidden
	CodeAlreadyExist
)

通用状态码

const (
	CodeInvalidLogin Code = 2000 + iota
	CodeInvalidSignup
	CodeOldPasswordNotMatch
	CodeNewPasswordNotMatch

	CodeNotFoundQueryID
	CodeNotFoundRouteParam
	CodeNotFoundUser
	CodeNotFoundUserID

	CodeAlreadyExistsUser
	CodeAlreadyExistsRole

	CodeTooLargeFile
)

业务状态码

func NewCode

func NewCode(code Code, status int, msg string) Code

func (Code) Code

func (r Code) Code() int

func (Code) Msg

func (r Code) Msg() string

func (Code) Status

func (r Code) Status() int

func (Code) WithErr

func (r Code) WithErr(err error) CodeInstance

func (Code) WithMsg

func (r Code) WithMsg(msg string) CodeInstance

func (Code) WithStatus

func (r Code) WithStatus(status int) CodeInstance

type CodeInstance

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

CodeInstance 表示一个错误码实例,包含自定义的状态和消息

func (CodeInstance) Code

func (ci CodeInstance) Code() int

func (CodeInstance) Msg

func (ci CodeInstance) Msg() string

func (CodeInstance) Status

func (ci CodeInstance) Status() int

func (CodeInstance) WithErr

func (ci CodeInstance) WithErr(err error) CodeInstance

func (CodeInstance) WithMsg

func (ci CodeInstance) WithMsg(msg string) CodeInstance

func (CodeInstance) WithStatus

func (ci CodeInstance) WithStatus(status int) CodeInstance

type Responder

type Responder interface {
	Msg() string
	Status() int
	Code() int
}

Responder 响应接口,统一处理 Code 和 CodeInstance

Jump to

Keyboard shortcuts

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