Response

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// SuccessCode 成功 相当于200
	SuccessCode = iota
	// FailCode 失败/通用错误中止 相当于500
	FailCode
	// ParameterErrorCode 参数错误 相当于400
	ParameterErrorCode
	// AccessAbortedCode 访问中止 相当于403
	AccessAbortedCode
	// AccessAbortedCallbackCode 访问中止回调 相当于403+302 跳转到黑名单,登陆失败/失效的提示,工作页面 登录时不建议使用
	AccessAbortedCallbackCode
)

0-9 为保留状态码

View Source
const (
	DefaultSuccessResponse           = `{"code":0,"msg":"ok"}`
	DefaultFailResponse              = `{"code":1,"msg":"Unknown error"}`
	DefaultSerializationFailResponse = `{"code":1,"msg":"Serialization error"}`
	DefaultParameterErrorResponse    = `{"code":2,"msg":"Error or missing parameter"}`
	DefaultAccessAbortedResponse     = `{"code":3,"msg":"AccessFail"}`
)

Variables

This section is empty.

Functions

func EasyJsonSuccess

func EasyJsonSuccess(data Fetch.EasyJsonSerialization) string

EasyJsonSuccess 成功响应,data建议传指针类型的值

func Fail

func Fail(err ExtErr.Err) string

Fail 失败响应

func IsSuccess

func IsSuccess(string2 string) bool

IsSuccess 快速判断是否成功,仅用于此包内生成的响应字符串

func Success

func Success(data any) string

Success 成功响应

Types

type EasyJsonResponse

type EasyJsonResponse struct {
	Code int
	Msg  string
	Data Fetch.EasyJsonSerialization
}

func (*EasyJsonResponse) IsSuccess added in v0.0.7

func (r *EasyJsonResponse) IsSuccess() bool

type Response

type Response struct {
	Code int    `json:"code"`
	Msg  string `json:"msg,omitempty"`
	Data any    `json:"data,omitempty"`
}

func (*Response) IsSuccess added in v0.0.7

func (r *Response) IsSuccess() bool

Jump to

Keyboard shortcuts

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