mirror of
https://github.com/wyx2685/V2bX.git
synced 2026-02-04 12:40:11 +00:00
fix some bugs
support ip limit for hy
This commit is contained in:
50
conf/conf.go
50
conf/conf.go
@@ -2,14 +2,9 @@ package conf
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"path"
|
||||
"time"
|
||||
|
||||
"github.com/fsnotify/fsnotify"
|
||||
"gopkg.in/yaml.v3"
|
||||
"io"
|
||||
"os"
|
||||
)
|
||||
|
||||
type Conf struct {
|
||||
@@ -56,44 +51,3 @@ func (p *Conf) LoadFromPath(filePath string) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *Conf) Watch(filePath string, reload func()) error {
|
||||
watcher, err := fsnotify.NewWatcher()
|
||||
if err != nil {
|
||||
return fmt.Errorf("new watcher error: %s", err)
|
||||
}
|
||||
go func() {
|
||||
var pre time.Time
|
||||
defer watcher.Close()
|
||||
for {
|
||||
select {
|
||||
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)
|
||||
if err != nil {
|
||||
log.Printf("reload config error: %s", err)
|
||||
}
|
||||
reload()
|
||||
log.Println("reload config success")
|
||||
case err := <-watcher.Errors:
|
||||
if err != nil {
|
||||
log.Printf("File watcher error: %s", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
err = watcher.Add(path.Dir(filePath))
|
||||
if err != nil {
|
||||
return fmt.Errorf("watch file error: %s", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user