优化code reason
This commit is contained in:
parent
be993da6db
commit
c293dcfa7f
@ -15,13 +15,13 @@ package exception
|
|||||||
type IException interface {
|
type IException interface {
|
||||||
// Error 兼容 go 内置 error
|
// Error 兼容 go 内置 error
|
||||||
Error() string
|
Error() string
|
||||||
// GetCode *获取错误码
|
// GetCode 获取错误码
|
||||||
GetCode() interface{}
|
GetCode() interface{}
|
||||||
// GetMessage *获取错误信息
|
// GetMessage *获取错误信息
|
||||||
GetMessage() string
|
GetMessage() string
|
||||||
// GetData 获取异常时的返回数据
|
// GetData 获取异常时的返回数据
|
||||||
GetData() interface{}
|
GetData() interface{}
|
||||||
// GetHttpCode *获取当前异常要返回的http状态码, 不设置则 默认 200
|
// GetHttpCode 获取当前异常要返回的http状态码, 不设置则 默认 200
|
||||||
GetHttpCode() int
|
GetHttpCode() int
|
||||||
// ToError 转换为内置error类型
|
// ToError 转换为内置error类型
|
||||||
ToError() error
|
ToError() error
|
||||||
|
32
code.go
32
code.go
@ -38,10 +38,7 @@ func InitCodeTableWithMessage(table map[interface{}]map[string]string, convertDe
|
|||||||
c := Code{
|
c := Code{
|
||||||
Value: code,
|
Value: code,
|
||||||
Message: message,
|
Message: message,
|
||||||
Reason: []*CodeReason{&CodeReason{
|
Reason: make(map[string][]*CodeReason),
|
||||||
Reason: message,
|
|
||||||
Solution: map[string][]string{},
|
|
||||||
}},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
codeTable[code] = c
|
codeTable[code] = c
|
||||||
@ -66,34 +63,15 @@ func InitCodeTableWithCodeList(list []Code, convertDefaultSuccessCode interface{
|
|||||||
codeList = list
|
codeList = list
|
||||||
for _, itemCode := range list {
|
for _, itemCode := range list {
|
||||||
if nil == itemCode.Reason {
|
if nil == itemCode.Reason {
|
||||||
itemCode.Reason = []*CodeReason{
|
itemCode.Reason = make(map[string][]*CodeReason)
|
||||||
{
|
|
||||||
Reason: map[string]string{},
|
|
||||||
Solution: map[string][]string{},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if nil == itemCode.Reason {
|
|
||||||
itemCode.Reason = make([]*CodeReason, 0)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, itemReason := range itemCode.Reason {
|
for lang, _ := range itemCode.Message {
|
||||||
if nil == itemReason.Solution {
|
if _, exist := itemCode.Reason[lang]; !exist {
|
||||||
itemReason.Solution = make(map[string][]string)
|
itemCode.Reason[lang] = make([]*CodeReason, 0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, itemReason := range itemCode.Reason {
|
|
||||||
for lang, _ := range itemReason.Reason {
|
|
||||||
if _, exist := itemReason.Solution[lang]; !exist {
|
|
||||||
itemReason.Solution[lang] = make([]string, 0)
|
|
||||||
}
|
|
||||||
if nil == itemReason.Solution[lang] {
|
|
||||||
itemReason.Solution[lang] = make([]string, 0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
codeTable[itemCode.Value] = itemCode
|
codeTable[itemCode.Value] = itemCode
|
||||||
}
|
}
|
||||||
if nil == convertDefaultSuccessCode {
|
if nil == convertDefaultSuccessCode {
|
||||||
|
@ -15,7 +15,7 @@ package exception
|
|||||||
type Code struct {
|
type Code struct {
|
||||||
Value interface{} `json:"value"` // 状态码的值
|
Value interface{} `json:"value"` // 状态码的值
|
||||||
Message map[string]string `json:"message"` // 状态码对应的文案(key -> 语言 , value -> 对应语言的描述)
|
Message map[string]string `json:"message"` // 状态码对应的文案(key -> 语言 , value -> 对应语言的描述)
|
||||||
Reason []*CodeReason `json:"reason"` // 产生此错误码的原因描述(key -> 语言 , value -> 对应语言的描述)
|
Reason map[string][]*CodeReason `json:"reason"` // 产生此错误码的原因描述(key -> 语言 , value -> 对应语言的原因列表)
|
||||||
}
|
}
|
||||||
|
|
||||||
// CodeReason 错误码的原因
|
// CodeReason 错误码的原因
|
||||||
@ -24,6 +24,6 @@ type Code struct {
|
|||||||
//
|
//
|
||||||
// Date : 00:31 2023/11/5
|
// Date : 00:31 2023/11/5
|
||||||
type CodeReason struct {
|
type CodeReason struct {
|
||||||
Reason map[string]string `json:"reason"` // 错误原因: 语言 => 原因
|
Reason string `json:"reason"` // 错误原因: 语言 => 原因
|
||||||
Solution map[string][]string `json:"solution"` // 解决步骤. 语言 => 解决步骤
|
Solution []string `json:"solution"` // 解决步骤. 语言 => 解决步骤
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user