serializer

package
v0.0.0-...-97a7533 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// CodeCheckLogin 未登录
	CodeCheckLogin = 401
	// CodeNoRightErr 未授权访问
	CodeNoRightErr = 403
	// CodeDBError 数据库操作失败
	CodeDBError = 50001
	// CodeEncryptError 加密失败
	CodeEncryptError = 50002
	//CodeParamErr 各种奇奇怪怪的参数错误
	CodeParamErr = 40001
	//toekn
	TokenError = 40002
)

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

Variables

This section is empty.

Functions

This section is empty.

Types

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 BuildLoginUserResponse

func BuildLoginUserResponse(user models.User, token string, code int) Response

func BuildRegisterUserResponse

func BuildRegisterUserResponse(user models.User, code int) Response

BuildUserResponse 序列化用户响应

func CheckLogin

func CheckLogin() Response

CheckLogin 检查登录

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 各种参数错误

func TokenGetCheck

func TokenGetCheck() Response

type TrackedErrorResponse

type TrackedErrorResponse struct {
	Response
	TrackID string `json:"track_id"`
}

TrackedErrorResponse 有追踪信息的错误响应

type User

type User struct {
	ID        uint   `json:"id"`
	UserName  string `json:"user_name"`
	Nickname  string `json:"nickname"`
	Status    string `json:"status"`
	Avatar    string `json:"avatar"`
	CreatedAt int64  `json:"created_at"`
	Token     string `json:"token"`
}

User 用户序列化器

func BuildLoginUser

func BuildLoginUser(user models.User, token string) User

BuildUser 序列化用户

func BuildRegisterUser

func BuildRegisterUser(user models.User) User

Jump to

Keyboard shortcuts

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