mirror of
https://github.com/wyx2685/V2bX.git
synced 2026-02-04 04:30:08 +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"
|
||||
"os"
|
||||
"path"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Conf struct {
|
||||
@@ -63,10 +64,19 @@ func (p *Conf) Watch(filePath string, reload func()) error {
|
||||
return fmt.Errorf("new watcher error: %s", err)
|
||||
}
|
||||
go func() {
|
||||
var pre time.Time
|
||||
defer watcher.Close()
|
||||
for {
|
||||
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...")
|
||||
*p = *New()
|
||||
err := p.LoadFromPath(filePath)
|
||||
|
||||
@@ -1,8 +1,19 @@
|
||||
package conf
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"log"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestConf_LoadFromPath(t *testing.T) {
|
||||
c := New()
|
||||
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