-
Notifications
You must be signed in to change notification settings - Fork 43
/
store.go
63 lines (49 loc) · 892 Bytes
/
store.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
60
61
62
package excel
import (
"encoding/json"
"io/ioutil"
"sync"
log "github.com/cihub/seelog"
)
type StoreData struct {
Id uint64
Type uint64
Name string
Price uint64
RelationID uint64
State uint64
}
var store map[uint64]StoreData
var storeLock sync.RWMutex
func LoadStore(){
storeLock.Lock()
defer storeLock.Unlock()
data,err := ioutil.ReadFile("../res/excel/store.json")
if err != nil {
log.Error("ReadFile err: ", err)
return
}
err = json.Unmarshal(data, &store)
if err != nil {
log.Error("Unmarshal err: ", err)
return
}
}
func GetStoreMap() map[uint64]StoreData {
storeLock.RLock()
defer storeLock.RUnlock()
store2 := make(map[uint64]StoreData)
for k, v := range store{
store2[k] = v
}
return store2
}
func GetStore(key uint64) (StoreData, bool) {
storeLock.RLock()
defer storeLock.RUnlock()
val, ok := store[key]
return val, ok
}
func GetStoreMapLen() int {
return len(store)
}