Merge pull request #95 from stitchrs/dev_dns

feat: remote dns config
This commit is contained in:
Yuzuki
2023-07-20 20:04:05 +08:00
committed by GitHub
4 changed files with 52 additions and 6 deletions

View File

@@ -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
}