-
Notifications
You must be signed in to change notification settings - Fork 0
/
filewatch.go
54 lines (46 loc) · 1.11 KB
/
filewatch.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
package server
import (
"github.com/askasoft/pango-xdemo/app"
"github.com/askasoft/pango/fsu"
"github.com/askasoft/pango/fsw"
"github.com/askasoft/pango/log"
)
// initFileWatch initialize file watch
func initFileWatch() {
fsw.Default().Logger = log.GetLogger("FSW")
err := fsw.Add(app.LogConfigFile, fsw.OpWrite, reloadLog)
if err == nil {
for _, f := range app.AppConfigFiles {
if err == nil && fsu.FileExists(f) == nil {
err = fsw.Add(f, fsw.OpWrite, reloadConfigs)
}
}
}
if err == nil {
msgPath := app.INI.GetString("app", "messages")
if msgPath != "" {
err = fsw.AddRecursive(msgPath, fsw.OpModifies, reloadMessages)
}
}
if err == nil {
tplPath := app.INI.GetString("app", "templates")
if tplPath != "" {
err = fsw.AddRecursive(tplPath, fsw.OpModifies, reloadTemplates)
}
}
if err != nil {
log.Fatal(err) //nolint: all
app.Exit(app.ExitErrFSW)
}
err = configFileWatch()
if err != nil {
log.Fatal(err) //nolint: all
app.Exit(app.ExitErrFSW)
}
}
func configFileWatch() error {
if app.INI.GetBool("app", "reloadable") {
return fsw.Start()
}
return fsw.Stop()
}