fix init table

This commit is contained in:
白茶清欢 2023-11-05 23:38:15 +08:00
parent 84811e426c
commit e8561a060c

14
code.go
View File

@ -38,7 +38,7 @@ func InitCodeTableWithMessage(table map[interface{}]map[string]string, convertDe
c := Code{ c := Code{
Value: code, Value: code,
Message: message, Message: message,
Reason: make(map[string][]*CodeReason), Reason: make([]*CodeReason, 0),
} }
codeTable[code] = c codeTable[code] = c
@ -63,13 +63,19 @@ 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 = make(map[string][]*CodeReason) itemCode.Reason = make([]*CodeReason, 0)
} }
for lang, _ := range itemCode.Message { for lang, _ := range itemCode.Message {
if _, exist := itemCode.Reason[lang]; !exist { for _, itemReason := range itemCode.Reason {
itemCode.Reason[lang] = make([]*CodeReason, 0) if _, exist := itemReason.Reason[lang]; !exist {
continue
}
if _, exist := itemReason.Solution[lang]; !exist {
itemReason.Solution[lang] = make([]string, 0)
}
} }
} }
codeTable[itemCode.Value] = itemCode codeTable[itemCode.Value] = itemCode