From e8561a060cc8efe779785e56d0c6645f666e5a0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Sun, 5 Nov 2023 23:38:15 +0800 Subject: [PATCH] fix init table --- code.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/code.go b/code.go index b8c3c35..1c0f6e0 100644 --- a/code.go +++ b/code.go @@ -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