From 292fcf083938098e1c6f00560d4fc4007a167e64 Mon Sep 17 00:00:00 2001 From: zhangdeman001 Date: Fri, 9 Jun 2023 16:20:14 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8C=89=E7=85=A7code=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E5=BC=82=E5=B8=B8=E7=A0=81=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- code.go | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/code.go b/code.go index 2dc1f14..f2a81cf 100644 --- a/code.go +++ b/code.go @@ -26,12 +26,12 @@ func init() { codeTable = make(map[interface{}]Code) } -// InitCodeTable 初始化码表, 同时只指定代表业务成功的状态码以及使用的语言 +// InitCodeTableWithMessage 初始化码表, 同时只指定代表业务成功的状态码以及使用的语言 // // Author : go_developer@163.com<白茶清欢> // // Date : 20:55 2022/6/25 -func InitCodeTable(table map[interface{}]map[string]string, convertDefaultSuccessCode interface{}, convertDefaultLanguage string) { +func InitCodeTableWithMessage(table map[interface{}]map[string]string, convertDefaultSuccessCode interface{}, convertDefaultLanguage string) { for code, message := range table { codeTable[code] = Code{ Value: code, @@ -50,6 +50,25 @@ func InitCodeTable(table map[interface{}]map[string]string, convertDefaultSucces defaultLanguage = convertDefaultLanguage } +// InitCodeTableWithCodeList 按照code列表初始化 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 16:19 2023/6/9 +func InitCodeTableWithCodeList(list []Code, convertDefaultSuccessCode interface{}, convertDefaultLanguage string) { + for _, itemCode := range list { + codeTable[itemCode.Value] = itemCode + } + if nil == convertDefaultSuccessCode { + convertDefaultSuccessCode = 0 + } + if len(convertDefaultLanguage) == 0 { + convertDefaultLanguage = defaultLanguage + } + defaultSuccessCode = convertDefaultSuccessCode + defaultLanguage = convertDefaultLanguage +} + var ( // messageWithCode 自动在message文案后追加状态码 messageWithCode = true