-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.go
53 lines (48 loc) · 1.4 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
package cmder
import (
"strings"
"github.com/admpub/nging/v5/application/initialize/backend"
"github.com/admpub/nging/v5/application/library/common"
"github.com/admpub/nging/v5/application/library/config"
"github.com/webx-top/echo"
)
func onServerConfigChange(file string) error {
id := config.FromCLI().GenerateIDFromConfigFileName(file, true)
if len(id) == 0 {
return common.ErrIgnoreConfigChange
}
if !config.FromCLI().IsRunning(`frpserver.` + id) {
return common.ErrIgnoreConfigChange
}
if cm, err := GetServer(); err == nil {
return cm.RestartBy(id)
}
return nil
}
func onClientConfigChange(file string) error {
id := config.FromCLI().GenerateIDFromConfigFileName(file, true)
if len(id) == 0 {
return common.ErrIgnoreConfigChange
}
if !config.FromCLI().IsRunning(`frpclient.` + id) {
return common.ErrIgnoreConfigChange
}
if cm, err := GetClient(); err == nil {
return cm.RestartBy(id)
}
return nil
}
func init() {
backend.OnConfigChange(func(filePath string) (err error) {
if strings.Contains(filePath, echo.FilePathSeparator+`frp`+echo.FilePathSeparator+`server`+echo.FilePathSeparator) {
err = onServerConfigChange(filePath)
}
return
})
backend.OnConfigChange(func(filePath string) (err error) {
if strings.Contains(filePath, echo.FilePathSeparator+`frp`+echo.FilePathSeparator+`client`+echo.FilePathSeparator) {
err = onClientConfigChange(filePath)
}
return
})
}