GoDoxy/src/watcher/file_watcher.go
2024-09-21 17:22:17 +08:00

29 lines
581 B
Go

package watcher
import (
"context"
"path"
"github.com/yusing/go-proxy/common"
E "github.com/yusing/go-proxy/error"
)
type fileWatcher struct {
filename string
}
func NewFileWatcher(filename string) Watcher {
if path.Base(filename) != filename {
panic("filename must be a relative path")
}
return &fileWatcher{filename: filename}
}
func (f *fileWatcher) Events(ctx context.Context) (<-chan Event, <-chan E.NestedError) {
if fwHelper == nil {
fwHelper = newFileWatcherHelper(common.ConfigBasePath)
}
return fwHelper.Add(ctx, f)
}
var fwHelper *fileWatcherHelper