serializer

package
v0.0.0-...-c285f8c Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CodeSuccess          = 200
	CodeUnauthorized     = 401  // 认证错误
	CodeForbidden        = 403  // 无权限
	CodeInternalError    = 1000 // 内部错误
	CodeDBError          = 1001 // 数据库错误
	CodeParamError       = 1002 // 参数错误
	CodeConditionNotMeet = 1003 // 条件不满足错误
	CodeAdminRequired    = 2000 // 需要为管理员账号
	CodeActiveRequired   = 2001 // 需要为激活账号
)

Variables

This section is empty.

Functions

func CreateParamErrorMsg

func CreateParamErrorMsg(filed string, tag string) string

Types

type Response

type Response struct {
	Code  int         `json:"code"`            // 响应代码
	Data  interface{} `json:"data,omitempty"`  // 数据
	Msg   string      `json:"msg"`             // 消息
	Error string      `json:"error,omitempty"` // 错误
}

响应体

func CreateDBErrorResponse

func CreateDBErrorResponse(msg string, err error) Response

func CreateErrorResponse

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

func CreateGeneralParamErrorResponse

func CreateGeneralParamErrorResponse(msg string, err error) Response

func CreateInternalErrorResponse

func CreateInternalErrorResponse(msg string, err error) Response

func CreateParamErrorResponse

func CreateParamErrorResponse(err error) Response

func CreateSuccessResponse

func CreateSuccessResponse(data interface{}, msg string) Response

func CreateUserResponse

func CreateUserResponse(user *model.User) Response

func GetUnauthorizedResponse

func GetUnauthorizedResponse() Response

GetUnauthorizedResponse 检查登录

type ServiceError

type ServiceError struct {
	Code     int
	Msg      string
	RawError error
}

func NewServiceError

func NewServiceError(code int, msg string, err error) ServiceError

func (ServiceError) Error

func (se ServiceError) Error() string

实现 error 接口,返回信息为内部 Msg

func (*ServiceError) WrapError

func (se *ServiceError) WrapError(err error) ServiceError

type UserDTO

type UserDTO struct {
	ID       string `json:"id"`
	Email    string `json:"user_name"`
	NickName string `json:"nickname"`
	IsAdmin  bool   `json:"is_admin"`
	Status   int    `json:"status"`
}

Jump to

Keyboard shortcuts

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