修改初始化
This commit is contained in:
@@ -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
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user