rsp

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2026 License: MIT Imports: 3 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	Client   SystemCode // 客户请求错误
	Internal            // 内部错误
	Remote              // 远程错误

	Auth         BizCode // Auth
	Captcha              // Captcha
	Database             // Database
	File                 // File
	RemoteConfig         // RemoteConfig
)

Variables

View Source
var (
	Success          = New(_ok, 0, 0, "成功")
	ErrUnknownErr    = New(Internal, 0, 0, "未知错误")
	ErrUnImplemented = New(Internal, 0, 1, "未实现")
	ErrNotFound      = New(Internal, 0, 2, "资源未找到")
	// Request
	ErrBadRequest   = New(Client, 0, 0, "请求不合法")
	ErrRequestLimit = New(Client, 0, 1, "请求过于频繁")
	ErrParamInvalid = New(Client, 0, 2, "参数不合法")
)
View Source
var (
	DatabaseUnknown  = New(Internal, Database, 0, "未知数据库错误")
	DatabaseExists   = New(Internal, Database, 1, "已存在")
	DatabaseUpdate   = New(Internal, Database, 2, "更新失败")
	DatabaseDelete   = New(Internal, Database, 3, "删除失败")
	DatabaseInsert   = New(Internal, Database, 4, "插入失败")
	DatabaseTruncate = New(Internal, Database, 5, "清空失败")
)
View Source
var (
	Unauthorized     = New(Client, Auth, 1, "未授权")  // Token Not Found in Request
	Forbidden        = New(Client, Auth, 2, "权限不足") // Permission Denied || Banned
	TokenInvalid     = New(Client, Auth, 3, "令牌无效")
	TokenExpired     = New(Client, Auth, 4, "令牌过期") // Token Not Found in Store
	PasswordInvalid  = New(Client, Auth, 5, "密码错误")
	PasswordWeak     = New(Client, Auth, 6, "密码强度不足")
	PasswordMatch    = New(Client, Auth, 7, "密码不匹配")
	PasswordReset    = New(Client, Auth, 8, "密码重置失败")
	EmailDisable     = New(Client, Auth, 9, "邮箱未开启")
	EmailCodeInvalid = New(Client, Auth, 10, "邮箱验证码无效")

	TokenCreate     = New(Internal, Auth, 1, "令牌创建失败")
	TokenDestory    = New(Internal, Auth, 2, "令牌销毁失败")
	RegisterExists  = New(Internal, Auth, 3, "用户已存在")
	RegisterFailed  = New(Internal, Auth, 4, "用户注册失败")
	RegisterDisable = New(Internal, Auth, 5, "用户注册已关闭")

	EmailCodeSend = New(Remote, Auth, 1, "邮箱验证码发送失败")
)

Auth

View Source
var (
	CaptchaInvalid  = New(Client, Captcha, 1, "验证码错误")
	CaptchaGenerate = New(Internal, Captcha, 1, "验证码生成失败")
)

Captcha

View Source
var (
	FileSize = New(Client, File, 1, "文件大小超出限制")
	FileType = New(Client, File, 2, "文件类型不支持")

	FileUpload = New(Internal, File, 1, "文件上传失败")
	FileOpen   = New(Internal, File, 2, "文件打开失败")
	FileParse  = New(Internal, File, 3, "文件解析失败")
	FileExport = New(Internal, File, 4, "文件导出失败")
)

File

View Source
var (
	Errors = map[int]*AppError{}
)

Functions

This section is empty.

Types

type AppError

type AppError struct {
	Msg  string `json:"msg"`
	Code int    `json:"code"`
}

func New

func New(system SystemCode, biz BizCode, code int, msg string) *AppError

func (*AppError) Error

func (a *AppError) Error() string

func (*AppError) WithError

func (a *AppError) WithError(err error) *AppError

func (*AppError) WithMsg

func (a *AppError) WithMsg(msg string) *AppError

type BizCode

type BizCode int

type IDRsp

type IDRsp[T uint64 | string] struct {
	ID   T      `json:"id,omitempty"`
	UUID string `json:"uuid,omitempty"`
}

type ItemRsp

type ItemRsp = Rsp[*Items]

func Item

func Item[T Number](total T, items any) ItemRsp

func ItemCode

func ItemCode(err *AppError) ItemRsp

func ItemExt

func ItemExt[T Number](total T, items any, ext any) ItemRsp

func ItemNone

func ItemNone() ItemRsp

type Items

type Items struct {
	Items any   `json:"items"`
	Ext   any   `json:"ext,omitempty"`
	Total int64 `json:"total"`
}

type Number

type Number interface {
	int | int64 | int32 | int16 | int8 | uint | uint64 | uint32 | uint16 | uint8
}

type Resp

type Resp = Rsp[any]

type Rsp

type Rsp[T any] struct {
	*AppError `json:",inline"`
	Data      T `json:"data"`
}

func S

func S[T any](data T) *Rsp[T]

type RspNone

type RspNone = Rsp[struct{}]

func C

func C(err error) *RspNone

C 将错误转换为响应,内部错误信息仅记录日志,不返回给客户端 防止敏感的内部错误信息泄露

func CWithMsg

func CWithMsg(err error, msg string) *RspNone

CWithMsg 返回自定义消息的错误响应,同时记录原始错误 用于需要给用户友好提示但不暴露内部错误的场景

func E

func E(err *AppError) *RspNone

func M

func M(msg string) *RspNone

func OK

func OK() *RspNone

func UnImplemented

func UnImplemented() *RspNone

type SystemCode

type SystemCode int

Jump to

Keyboard shortcuts

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