protocol

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2023 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SystemError        = 1000000
	DBError            = 1000001
	CacheError         = 1000002
	ThirdServiceError  = 1000003
	ParamsLost         = 1000100
	ParamsNotValid     = 1000101
	ResouceNotExist    = 1000102
	DataOutOfThreshold = 1000103
	FrequentOpration   = 1000104
	RepeatOpration     = 1000105
	IllegalRequest     = 1000106
	DataHasExists      = 1000107
	PermissionDenied   = 1000108
	AntiCheating       = 1000109
	UnsupportClient    = 1000110
	UnsupportOs        = 1000111
	AccountFrozen      = 1000200
	AccountLock        = 1000201
	TokenError         = 1000202
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

type Error struct {
	Code int
	Err  error
}

Error 用来将运行错误包装成标准协议的错误

func (*Error) Error

func (e *Error) Error() string

func (*Error) HttpBody

func (e *Error) HttpBody() (int, *HttpBody)

func (*Error) Unwrap

func (e *Error) Unwrap() error

type HttpBody

type HttpBody struct {
	Code    int         `json:"code"`
	Message string      `json:"message"`
	Data    interface{} `json:"data"`
}

HttpBody 是写入http body的json数据结构

func ErrorJsonBody

func ErrorJsonBody(errorCode int) (int, *HttpBody)

ErrorJsonBody 生成错误信息的http code和body

func Fail

func Fail(code int, message string) (statusCode int, body *HttpBody)

Fail 业务处理失败

func JsonBody

func JsonBody(data interface{}) (statusCode int, body *HttpBody)

JsonBody 生成成功回复的http code和body

func Response

func Response(status int, code int, message string, data interface{}) (statusCode int, body *HttpBody)

Response 通用业务处理

func Result

func Result(code int, message string, data interface{}) (statusCode int, body *HttpBody)

Result 业务处理结果

func Success

func Success(data interface{}) (statusCode int, body *HttpBody)

Success 业务处理成功

func (*HttpBody) GetError

func (b *HttpBody) GetError() *Error

GetError 判断回复是否错误,如果是则返回对应错误对象

Jump to

Keyboard shortcuts

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