result

package
v1.4.10 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2023 License: Apache-2.0 Imports: 4 Imported by: 1

Documentation

Index

Constants

View Source
const (
	CodeBoolOk   = true
	CodeIntOk    = 0
	CodeBoolFail = false
)
View Source
const (
	OK           = "OK"
	Fail         = "Fail"
	Created      = "Created"
	Accepted     = "Accepted"
	NoContent    = "No Content"
	ResetContent = "Reset Content"

	BadRequest   = "Bad Request"
	Unauthorized = "Unauthorized"
	Forbidden    = "Forbidden"
	NotFound     = "Not Found"

	InternalServerError   = "Internal Server Error"
	InternalServerTimeout = "Internal Server Processing Timeout"
)
View Source
const (
	MessageOK           = "请求成功"
	MessageCreated      = "已成功创建资源"
	MessageAccepted     = "已经接受请求, 处理中"
	MessageNoContent    = "处理成功, 无其他响应信息"
	MessageResetContent = "已成功重置数据"

	MessageFail         = "请求失败"
	MessageBadRequest   = "请求的语法错误,服务器无法理解"
	MessageUnauthorized = "身份未认证"
	MessageForbidden    = "没有权限, 请求被服务器拒绝了"
	MessageNotFound     = "所请求的资源不存在"

	MessageInternalServerError   = "服务器内部错误, 无法完成请求"
	MessageInternalServerTimeout = "服务器处理超时"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Err

type Err struct {
	Message string `json:"message"`
	// contains filtered or unexported fields
}

func Error

func Error(msg string) *Err

func Error2Err

func Error2Err(err error) *Err

func Errorf

func Errorf(format string, args ...interface{}) *Err

func WrapError

func WrapError(err error, msg string) *Err

func WrapErrorf

func WrapErrorf(err error, code interface{}, format string, args ...interface{}) *Err

func (*Err) Error

func (err *Err) Error() string

func (*Err) StatusCode

func (err *Err) StatusCode() int

func (*Err) WithStatusCode

func (err *Err) WithStatusCode(statusCode int) *Err

type Json

type Json map[string]interface{}

func (Json) Get

func (j Json) Get(key string) interface{}

func (Json) Set

func (j Json) Set(key string, val interface{}) Json

func (Json) String

func (j Json) String() string

type Result

type Result struct {
	Code    bool        `json:"code"`
	Message string      `json:"message"`
	Data    interface{} `json:"data"`
	// contains filtered or unexported fields
}

func Failed

func Failed(msg string) *Result

func FailedWithErr

func FailedWithErr(err error) *Result

func FailedWithFormat

func FailedWithFormat(format string, args ...interface{}) *Result

func New

func New() *Result

func Succeed

func Succeed(data interface{}) *Result

func (*Result) StatusCode

func (res *Result) StatusCode() int

func (*Result) WithMessage

func (res *Result) WithMessage(msg string) *Result

func (*Result) WithStatusCode

func (res *Result) WithStatusCode(statusCode int) *Result

func (*Result) WithSubResult

func (res *Result) WithSubResult(subResult *SubResult) *Result

type SubResult

type SubResult struct {
	SubCode    interface{} `json:"sub_code"`
	SubData    interface{} `json:"sub_data"`
	SubMessage string      `json:"sub_message"`
}

func NewSubResult

func NewSubResult(subCode interface{}, subMsg string) *SubResult

func (*SubResult) WithCode

func (sub *SubResult) WithCode(subCode interface{}) *SubResult

func (*SubResult) WithData

func (sub *SubResult) WithData(subData interface{}) *SubResult

func (*SubResult) WithMessage

func (sub *SubResult) WithMessage(subMsg string) *SubResult

Jump to

Keyboard shortcuts

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