-
Notifications
You must be signed in to change notification settings - Fork 43
/
init.go
135 lines (118 loc) · 2.8 KB
/
init.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package excel
import (
"encoding/json"
"io/ioutil"
"strings"
log "github.com/cihub/seelog"
"github.com/fsnotify/fsnotify"
)
type LoadFunc func()
var loadFuncs = map[string]LoadFunc{
"AIbirthdeath_SafeCircle":LoadAIbirthdeath_SafeCircle,
"AIbirthdeath_Server":LoadAIbirthdeath_Server,
"AImatch":LoadAImatch,
"Sadscore": LoadSadscore,
"AInumber": LoadAInumber,
"LoadingTips": LoadLoadingTips,
"Errorcode": LoadErrorcode,
"Item": LoadItem,
"Mapitem": LoadMapitem,
"Mapitemrate": LoadMapitemrate,
"Logic": LoadLogic,
"Carrier": LoadCarrier,
"Bombrule": LoadBombrule,
"Parachuting": LoadParachuting,
"Meterfix": LoadMeterfix,
"Season": LoadSeason,
"Rating": LoadRating,
"Role": LoadRole,
"Energy": LoadEnergy,
"Adkey": LoadAdkey,
"Barrier": LoadBarrier,
"Gun": LoadGun,
"Clothes": LoadClothes,
"Phonenumber": LoadPhonenumber,
"Achievement": LoadAchievement,
"Detail": LoadDetail,
"Keywords": LoadKeywords,
"Characterstate": LoadCharacterstate,
"Skybox": LoadSkybox,
"Maps": LoadMaps,
"Maprule": LoadMaprule,
"Store": LoadStore,
"Resultcoin": LoadResultcoin,
"Name": LoadName,
"Birthplace": LoadBirthplace,
"Pay": LoadPay,
"Rating2": LoadRating2,
"System": LoadSystem,
"Ai": LoadAi,
}
func init() {
for _, f := range loadFuncs {
f()
}
go func() {
watcher, err := fsnotify.NewWatcher()
if err != nil {
log.Error(err)
return
}
defer watcher.Close()
done := make(chan bool)
go func() {
for {
select {
case ev := <-watcher.Events:
log.Infof("Watch %s Op %s", ev.Name, ev.Op)
if strings.Contains(ev.Name, "reload.json") {
if ev.Op&fsnotify.Write == fsnotify.Write || ev.Op&fsnotify.Create == fsnotify.Create {
log.Info("Start Reload!")
if err := Reload("../res/excel/reload.json"); err != nil {
log.Error("Reload failed ", err)
} else {
log.Info("Reload excel success")
}
}
}
case err := <-watcher.Errors:
log.Error(err)
}
}
}()
if err = watcher.Add("../res/excel/"); err != nil {
log.Error(err)
} else {
log.Info("Watch excel path")
}
<-done
}()
}
func Reload(path string) error {
data, err := ioutil.ReadFile(path)
if err != nil {
return err
}
config := make(map[string]bool)
err = json.Unmarshal(data, &config)
if err != nil {
return err
}
for k, v := range config {
if v {
f, ok := loadFuncs[k]
if ok {
log.Info("Reload ", k)
f()
} else {
log.Error("Reload ", k, " failed, can't find the load function")
}
}
}
return nil
}
func ReloadAll() {
for _, f := range loadFuncs {
f()
}
}