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[any]Code
- func GetMessage(code any, defaultMessage ...string) string
- func InitCodeTableWithCodeList(list []Code, convertDefaultSuccessCode any, convertDefaultLanguage string)
- func InitCodeTableWithMessage(table map[any]map[string]string, convertDefaultSuccessCode any, ...)
- func IsSuccess(e *Exception) bool
- func MessageWithoutCode()
- type Code
- type Exception
- type IException
- func New(code any, data any, defaultMessage ...string) IException
- func NewFromError(code any, err error) IException
- func NewFromMessage(code any, message string) IException
- func NewSuccess(data any) IException
- func NewWithCode(code any) IException
- func NewWithCodeAndData(code any, data map[string]any) IException
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func InitCodeTableWithCodeList ¶
func InitCodeTableWithCodeList(list []Code, convertDefaultSuccessCode any, convertDefaultLanguage string)
InitCodeTableWithCodeList 按照code列表初始化
Author : go_developer@163.com<白茶清欢>
Date : 16:19 2023/6/9
func InitCodeTableWithMessage ¶
func InitCodeTableWithMessage(table map[any]map[string]string, convertDefaultSuccessCode any, 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 any `json:"value"` // 状态码的值 Message map[string]string `json:"message"` // 状态码对应的文案(key -> 语言 , value -> 对应语言的描述) Reason map[string]string `json:"reason"` // 产生此错误码的原因描述(key -> 语言 , value -> 对应语言的原因列表) Resolve map[string]string `json:"resolve"` // 解决此错误码的方案描述(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 Exception ¶
type Exception struct {
// contains filtered or unexported fields
}
Exception 异常接口的具体实现
Author : go_developer@163.com<白茶清欢>
Date *: 21:09 2022/6/25
type IException ¶
type IException interface { // Error 兼容 go 内置 error Error() string // Code 获取错误码 Code() any // Message 获取错误信息 Message() string // Data 获取异常时的返回数据 Data() any // ToError 转换为内置error类型 ToError() error // IsCode 是否为指定code IsCode(code any) bool // GetStack 获取调用堆栈 GetStack() string }
IException 异常的接口定义
Author : go_developer@163.com<白茶清欢>
Date *: 21:05 2022/6/25
func New ¶
func New(code any, data any, defaultMessage ...string) IException
New 获取异常实例
Author : go_developer@163.com<白茶清欢>
Date : 21:28 2022/6/25
func NewFromError ¶
func NewFromError(code any, err error) IException
NewFromError 从error转换为Exception
Author : go_developer@163.com<白茶清欢>
Date : 21:36 2022/6/25
func NewFromMessage ¶
func NewFromMessage(code any, message string) IException
NewFromMessage 从 code message 生成exception
Author : go_developer@163.com<白茶清欢>
Date : 22:25 2023/2/11
func NewSuccess ¶
func NewSuccess(data any) IException
NewSuccess 代表Success的异常
Author : go_developer@163.com<白茶清欢>
Date : 22:35 2022/6/25
func NewWithCode ¶
func NewWithCode(code any) IException
NewWithCode 仅使用错误码实例化异常
Author : go_developer@163.com<白茶清欢>
Date : 21:22 2022/6/25
func NewWithCodeAndData ¶
func NewWithCodeAndData(code any, data map[string]any) IException
NewWithCodeAndData 使用 code + data 获取异常实例
Author : go_developer@163.com<白茶清欢>
Date : 21:28 2022/6/25