fix init table

This commit is contained in:
白茶清欢 2023-11-05 23:38:15 +08:00
parent 84811e426c
commit e8561a060c
1 changed files with 10 additions and 4 deletions

14
code.go
View File

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