From 175e36ebd79cf80356bf743f603daddcd15681aa Mon Sep 17 00:00:00 2001 From: Yun <995116474@qq.com> Date: Mon, 14 Apr 2025 17:03:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=B8=80=E4=B8=8B=E9=94=81?= =?UTF-8?q?=E7=9A=84=E4=BD=BF=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- langx.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/langx.go b/langx.go index 935216a..7801680 100644 --- a/langx.go +++ b/langx.go @@ -16,7 +16,7 @@ type langx struct { ops *options codeMap map[string]int transMap map[string]map[string]string - mut sync.Mutex + mut sync.RWMutex } var l *langx = &langx{} @@ -27,7 +27,7 @@ func init() { ops: defaultOptions(), codeMap: make(map[string]int), transMap: make(map[string]map[string]string), - mut: sync.Mutex{}, + mut: sync.RWMutex{}, } } @@ -211,8 +211,8 @@ func GetTransFormatCtx(ctx context.Context, key string, format map[string]string // 根据Key获取code func GetCode(key string) int { - l.mut.Lock() - defer l.mut.Unlock() + l.mut.RLock() + defer l.mut.RUnlock() code, ok := l.codeMap[key] if !ok { return l.ops.defaultCode @@ -222,8 +222,8 @@ func GetCode(key string) int { // 获取翻译 func GetMsg(lang string, key string) string { - l.mut.Lock() - defer l.mut.Unlock() + l.mut.RLock() + defer l.mut.RUnlock() // 找指定语言 str, ok := l.transMap[lang] if ok {