mirror of
https://github.com/wyx2685/V2bX.git
synced 2026-02-04 12:40:11 +00:00
add wait many change for watcher
This commit is contained in:
12
conf/conf.go
12
conf/conf.go
@@ -8,6 +8,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Conf struct {
|
type Conf struct {
|
||||||
@@ -63,10 +64,19 @@ func (p *Conf) Watch(filePath string, reload func()) error {
|
|||||||
return fmt.Errorf("new watcher error: %s", err)
|
return fmt.Errorf("new watcher error: %s", err)
|
||||||
}
|
}
|
||||||
go func() {
|
go func() {
|
||||||
|
var pre time.Time
|
||||||
defer watcher.Close()
|
defer watcher.Close()
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-watcher.Events:
|
case e := <-watcher.Events:
|
||||||
|
if e.Has(fsnotify.Chmod) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if pre.Add(1 * time.Second).After(time.Now()) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
time.Sleep(2 * time.Second)
|
||||||
|
pre = time.Now()
|
||||||
log.Println("config dir changed, reloading...")
|
log.Println("config dir changed, reloading...")
|
||||||
*p = *New()
|
*p = *New()
|
||||||
err := p.LoadFromPath(filePath)
|
err := p.LoadFromPath(filePath)
|
||||||
|
|||||||
@@ -1,8 +1,19 @@
|
|||||||
package conf
|
package conf
|
||||||
|
|
||||||
import "testing"
|
import (
|
||||||
|
"log"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
func TestConf_LoadFromPath(t *testing.T) {
|
func TestConf_LoadFromPath(t *testing.T) {
|
||||||
c := New()
|
c := New()
|
||||||
t.Log(c.LoadFromPath("../example/config.yml.example"), c.NodesConfig[0].ControllerConfig.LimitConfig.IPLimit)
|
t.Log(c.LoadFromPath("../example/config.yml.example"), c.NodesConfig[0].ControllerConfig.LimitConfig.IPLimit)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestConf_Watch(t *testing.T) {
|
||||||
|
c := New()
|
||||||
|
c.Watch("../example/config.yml.example", func() {
|
||||||
|
log.Println(1)
|
||||||
|
})
|
||||||
|
select {}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user