Documentation ¶
Overview ¶
Package exception ...
Description : exception ...
Author : go_developer@163.com<白茶清欢>
Date : 2022-06-25 21:11
Package exception ...
Description : exception ...
Author : go_developer@163.com<白茶清欢>
Date : 2022-06-25 21:03
Package exception ...
Description : exception ...
Author : go_developer@163.com<白茶清欢>
Date : 2023-06-09 15:54
Package exception ...
Description : exception ...
Author : go_developer@163.com<白茶清欢>
Date *: 2022-06-25 21:04
Index ¶
- func GetCodeTable() map[interface{}]Code
- func GetMessage(code interface{}, defaultMessage ...string) string
- func InitCodeTableWithCodeList(list []Code, convertDefaultSuccessCode interface{}, ...)
- func InitCodeTableWithMessage(table map[interface{}]map[string]string, convertDefaultSuccessCode interface{}, ...)
- func IsSuccess(e *Exception) bool
- func MessageWithoutCode()
- func ToError(e *Exception) error
- type Code
- type CodeReason
- type Exception
- type IException
- func New(code interface{}, httpCode int, data interface{}, defaultMessage ...string) IException
- func NewFromError(code interface{}, err error) IException
- func NewFromMessage(code interface{}, message string) IException
- func NewSuccess(data interface{}) IException
- func NewWithCode(code interface{}) IException
- func NewWithCodeAndData(code interface{}, data interface{}) IException
- func NewWithCodeAndHttpCode(code interface{}, httpCode int) IException
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetCodeTable ¶
func GetCodeTable() map[interface{}]Code
GetCodeTable ...
Author : go_developer@163.com<白茶清欢>
Date : 18:05 2023/6/9
func InitCodeTableWithCodeList ¶
func InitCodeTableWithCodeList(list []Code, convertDefaultSuccessCode interface{}, convertDefaultLanguage string)
InitCodeTableWithCodeList 按照code列表初始化
Author : go_developer@163.com<白茶清欢>
Date : 16:19 2023/6/9
func InitCodeTableWithMessage ¶
func InitCodeTableWithMessage(table map[interface{}]map[string]string, convertDefaultSuccessCode interface{}, convertDefaultLanguage string)
InitCodeTableWithMessage 初始化码表, 同时只指定代表业务成功的状态码以及使用的语言
Author : go_developer@163.com<白茶清欢>
Date : 20:55 2022/6/25
func MessageWithoutCode ¶
func MessageWithoutCode()
MessageWithoutCode 关闭在文案后追加状态码
Author : go_developer@163.com<白茶清欢>
Date : 21:15 2022/6/25
Types ¶
type Code ¶
type Code struct { Value interface{} `json:"value"` // 状态码的值 Message map[string]string `json:"message"` // 状态码对应的文案(key -> 语言 , value -> 对应语言的描述) Reason []*CodeReason `json:"reason"` // 产生此错误码的原因描述(key -> 语言 , value -> 对应语言的原因列表) }
Code 状态码的结构
Author : go_developer@163.com<白茶清欢>
Date : 15:55 2023/6/9
func GetCodeList ¶
func GetCodeList() []Code
GetCodeList ...
Author : go_developer@163.com<白茶清欢>
Date : 18:04 2023/6/9
type CodeReason ¶
type CodeReason struct { Reason map[string]string `json:"reason"` // 错误原因: 语言 => 原因 Solution map[string][]string `json:"solution"` // 解决步骤. 语言 => 解决步骤 }
CodeReason 错误码的原因
Author : go_developer@163.com<白茶清欢>
Date : 00:31 2023/11/5
type Exception ¶
type Exception struct {
// contains filtered or unexported fields
}
Exception 异常接口的具体实现
Author : go_developer@163.com<白茶清欢>
Date *: 21:09 2022/6/25
func (*Exception) GetHttpCode ¶
func (*Exception) GetMessage ¶
type IException ¶
type IException interface { // Error 兼容 go 内置 error Error() string // GetCode 获取错误码 GetCode() interface{} // GetMessage *获取错误信息 GetMessage() string // GetData 获取异常时的返回数据 GetData() interface{} // GetHttpCode 获取当前异常要返回的http状态码, 不设置则 默认 200 GetHttpCode() int // ToError 转换为内置error类型 ToError() error // IsCode 是否为指定code IsCode(code interface{}) bool }
IException 异常的接口定义
Author : go_developer@163.com<白茶清欢>
Date *: 21:05 2022/6/25
func New ¶
func New(code interface{}, httpCode int, data interface{}, defaultMessage ...string) IException
New 获取异常实例
Author : go_developer@163.com<白茶清欢>
Date : 21:28 2022/6/25
func NewFromError ¶
func NewFromError(code interface{}, err error) IException
NewFromError 从error转换为Exception
Author : go_developer@163.com<白茶清欢>
Date : 21:36 2022/6/25
func NewFromMessage ¶
func NewFromMessage(code interface{}, message string) IException
NewFromMessage 从 code message 生成exception
Author : go_developer@163.com<白茶清欢>
Date : 22:25 2023/2/11
func NewSuccess ¶
func NewSuccess(data interface{}) IException
NewSuccess 代表Success的异常
Author : go_developer@163.com<白茶清欢>
Date : 22:35 2022/6/25
func NewWithCode ¶
func NewWithCode(code interface{}) IException
NewWithCode 仅使用错误码实例化异常
Author : go_developer@163.com<白茶清欢>
Date : 21:22 2022/6/25
func NewWithCodeAndData ¶
func NewWithCodeAndData(code interface{}, data interface{}) IException
NewWithCodeAndData 使用 code + data 获取异常实例
Author : go_developer@163.com<白茶清欢>
Date : 21:28 2022/6/25
func NewWithCodeAndHttpCode ¶
func NewWithCodeAndHttpCode(code interface{}, httpCode int) IException
NewWithCodeAndHttpCode 使用 code + http_code 获取实例
Author : go_developer@163.com<白茶清欢>
Date : 21:25 2022/6/25