tractor.dev/toolkit-go@v0.0.0-20241010005851-214d91207d07/engine/fs/watchfs/watch.go (about) 1 package watchfs 2 3 import ( 4 "errors" 5 "fmt" 6 "io/fs" 7 ) 8 9 type WatchFS interface { 10 fs.FS 11 // Wrapper Filesystems should check their children for implementations before providing their own. 12 // Return `errors.ErrUnsupported` to signal that parent Filesystems should use their implementation instead. 13 Watch(name string, cfg *Config) (*Watch, error) 14 } 15 16 func WatchFile(fsys fs.FS, name string, cfg *Config) (*Watch, error) { 17 if fsys, ok := fsys.(WatchFS); ok { 18 return fsys.Watch(name, cfg) 19 } 20 21 return nil, fmt.Errorf("watch %s: %w", name, errors.ErrUnsupported) 22 }