serializer

package
v0.0.0-...-5a8df17 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2022 License: GPL-3.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// CodeNotFullySuccess 未完全成功
	CodeNotFullySuccess = 203
	// CodeNoPermissionErr 未授权访问
	CodeNoPermissionErr = 403
	// CodeNotFound 资源未找到
	CodeNotFound = 404
	// CodeDBError 数据库操作失败
	CodeDBError = 50001
	//CodeParamErr 各种奇奇怪怪的参数错误
	CodeParamErr = 40001
	// CodeNotSet 未定错误,后续尝试从error中获取
	CodeNotSet = -1
)

三位数错误编码为复用http原本含义 五位数错误编码为应用自定义错误 五开头的五位数错误编码为服务器端错误,比如数据库操作失败 四开头的五位数错误编码为客户端错误,有时候是客户端代码写错了,有时候是用户操作错误

Variables

This section is empty.

Functions

This section is empty.

Types

type AppError

type AppError struct {
	Code     int
	Msg      string
	RawError error
}

AppError 应用错误,实现了error接口

func NewError

func NewError(code int, msg string, err error) AppError

NewError 返回新的错误对象

func (AppError) Error

func (err AppError) Error() string

Error 返回业务代码确定的可读错误信息

func (*AppError) WithError

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

WithError 将应用error携带标准库中的error

type Response

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

Response 基础序列化器

func DBErr

func DBErr(msg string, err error) Response

DBErr 数据库操作失败

func Err

func Err(errCode int, msg string, err error) Response

Err 通用错误处理

func ParamErr

func ParamErr(msg string, err error) Response

ParamErr 各种参数错误

Jump to

Keyboard shortcuts

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