修改初始化

This commit is contained in:
yun
2025-10-26 16:15:42 +08:00
parent 8aaf4fe712
commit 914a74d05e
+12 -6
View File
@@ -19,22 +19,20 @@ type langx struct {
mut sync.RWMutex mut sync.RWMutex
} }
var l *langx = &langx{} var l *langx = &langx{
func init() {
l = &langx{
ops: defaultOptions(), ops: defaultOptions(),
codeMap: make(map[string]int), codeMap: make(map[string]int),
transMap: make(map[string]map[string]string), transMap: make(map[string]map[string]string),
mut: sync.RWMutex{}, mut: sync.RWMutex{},
} }
}
// 这是语言的Code // 这是语言的Code
func RegisterCode(datas map[string]int) { func RegisterCode(datas map[string]int) {
l.mut.Lock() l.mut.Lock()
defer l.mut.Unlock() defer l.mut.Unlock()
if datas == nil {
datas = make(map[string]int)
}
l.codeMap = datas l.codeMap = datas
} }
@@ -42,6 +40,14 @@ func RegisterCode(datas map[string]int) {
func AppendCode(datas map[string]int) { func AppendCode(datas map[string]int) {
l.mut.Lock() l.mut.Lock()
defer l.mut.Unlock() defer l.mut.Unlock()
if datas == nil {
datas = make(map[string]int)
}
if l.codeMap == nil {
l.codeMap = map[string]int{}
}
for k, v := range datas { for k, v := range datas {
l.codeMap[k] = v l.codeMap[k] = v
} }