mirror of
https://github.com/wyx2685/V2bX.git
synced 2026-02-04 12:40:11 +00:00
@@ -8,7 +8,7 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
func (p *Conf) Watch(filePath string, reload func()) error {
|
||||
func (p *Conf) Watch(filePath, dnsPath string, reload func()) error {
|
||||
watcher, err := fsnotify.NewWatcher()
|
||||
if err != nil {
|
||||
return fmt.Errorf("new watcher error: %s", err)
|
||||
@@ -28,7 +28,11 @@ func (p *Conf) Watch(filePath string, reload func()) error {
|
||||
pre = time.Now()
|
||||
go func() {
|
||||
time.Sleep(10 * time.Second)
|
||||
log.Println("config dir changed, reloading...")
|
||||
if e.Name == dnsPath {
|
||||
log.Println("DNS file changed, reloading...")
|
||||
} else {
|
||||
log.Println("config dir changed, reloading...")
|
||||
}
|
||||
*p = *New()
|
||||
err := p.LoadFromPath(filePath)
|
||||
if err != nil {
|
||||
@@ -48,5 +52,11 @@ func (p *Conf) Watch(filePath string, reload func()) error {
|
||||
if err != nil {
|
||||
return fmt.Errorf("watch file error: %s", err)
|
||||
}
|
||||
if dnsPath != "" {
|
||||
err = watcher.Add(path.Dir(dnsPath))
|
||||
if err != nil {
|
||||
return fmt.Errorf("watch dns file error: %s", err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user