update code define
This commit is contained in:
67
code.go
67
code.go
@@ -36,11 +36,14 @@ func init() {
|
||||
func InitCodeTableWithMessage(table map[interface{}]map[string]string, convertDefaultSuccessCode interface{}, convertDefaultLanguage string) {
|
||||
for code, message := range table {
|
||||
c := Code{
|
||||
Value: code,
|
||||
Message: message,
|
||||
Reason: message,
|
||||
Solution: map[string]interface{}{},
|
||||
Value: code,
|
||||
Message: message,
|
||||
Reason: []*CodeReason{&CodeReason{
|
||||
Reason: message,
|
||||
Solution: map[string][]string{},
|
||||
}},
|
||||
}
|
||||
|
||||
codeTable[code] = c
|
||||
codeList = append(codeList, c)
|
||||
}
|
||||
@@ -62,8 +65,34 @@ func InitCodeTableWithMessage(table map[interface{}]map[string]string, convertDe
|
||||
func InitCodeTableWithCodeList(list []Code, convertDefaultSuccessCode interface{}, convertDefaultLanguage string) {
|
||||
codeList = list
|
||||
for _, itemCode := range list {
|
||||
if itemCode.Reason == nil || len(itemCode.Reason) == 0 {
|
||||
itemCode.Reason = itemCode.Message
|
||||
if nil == itemCode.Reason {
|
||||
itemCode.Reason = []*CodeReason{
|
||||
{
|
||||
Reason: map[string]string{},
|
||||
Solution: map[string][]string{},
|
||||
},
|
||||
}
|
||||
}
|
||||
if nil == itemCode.Reason {
|
||||
itemCode.Reason = make([]*CodeReason, 0)
|
||||
}
|
||||
|
||||
for _, itemReason := range itemCode.Reason {
|
||||
if nil == itemReason.Solution {
|
||||
itemReason.Solution = make(map[string][]string)
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
@@ -147,29 +176,3 @@ func GetCodeList() []Code {
|
||||
func GetCodeTable() map[interface{}]Code {
|
||||
return codeTable
|
||||
}
|
||||
|
||||
// getReason 获取真实失败原因描述
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 18:09 2023/6/9
|
||||
func getReason(code interface{}) string {
|
||||
inputCodeInfo, exist := codeTable[code]
|
||||
if !exist {
|
||||
return getMessage(code, "")
|
||||
}
|
||||
return inputCodeInfo.Reason[defaultLanguage]
|
||||
}
|
||||
|
||||
// getSolution 获取解决方案
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 18:10 2023/6/9
|
||||
func getSolution(code interface{}) map[string]interface{} {
|
||||
inputCodeInfo, exist := codeTable[code]
|
||||
if !exist {
|
||||
return map[string]interface{}{}
|
||||
}
|
||||
return inputCodeInfo.Solution
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user