-
Notifications
You must be signed in to change notification settings - Fork 43
/
mapitem.go
60 lines (46 loc) · 898 Bytes
/
mapitem.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package excel
import (
"encoding/json"
"io/ioutil"
"sync"
log "github.com/cihub/seelog"
)
type MapitemData struct {
Id uint64
Zone string
Rate uint64
}
var mapitem map[uint64]MapitemData
var mapitemLock sync.RWMutex
func LoadMapitem(){
mapitemLock.Lock()
defer mapitemLock.Unlock()
data,err := ioutil.ReadFile("../res/excel/mapitem.json")
if err != nil {
log.Error("ReadFile err: ", err)
return
}
err = json.Unmarshal(data, &mapitem)
if err != nil {
log.Error("Unmarshal err: ", err)
return
}
}
func GetMapitemMap() map[uint64]MapitemData {
mapitemLock.RLock()
defer mapitemLock.RUnlock()
mapitem2 := make(map[uint64]MapitemData)
for k, v := range mapitem{
mapitem2[k] = v
}
return mapitem2
}
func GetMapitem(key uint64) (MapitemData, bool) {
mapitemLock.RLock()
defer mapitemLock.RUnlock()
val, ok := mapitem[key]
return val, ok
}
func GetMapitemMapLen() int {
return len(mapitem)
}