diff --git a/README.md b/README.md index 80ab820..0529917 100644 --- a/README.md +++ b/README.md @@ -73,13 +73,12 @@ func main() { ``` ### Watching files for changes -The `koanf.Provider` interface has a `Watch(cb)` method that asks a provider -to watch for changes and trigger the given callback that can live reload the -configuration. This is not goroutine safe if there are concurrent `*Get()` -calls happening on the koanf object while it is doing a `Load()`. Such -scenarios will need mutex locking. +Some providers expose a `Watch()` method that makes the provider watch for changes +in configuration and trigger a callback to reload the configuration. +This is not goroutine safe if there are concurrent `*Get()` calls happening on the +koanf object while it is doing a `Load()`. Such scenarios will need mutex locking. -Currently, `file.Provider` supports this. +`file, appconfig, vault, consul` providers have a `Watch()` method. ```go diff --git a/providers/basicflag/basicflag.go b/providers/basicflag/basicflag.go index 4e4889e..6dbf9ba 100644 --- a/providers/basicflag/basicflag.go +++ b/providers/basicflag/basicflag.go @@ -62,8 +62,3 @@ func (p *Pflag) Read() (map[string]interface{}, error) { func (p *Pflag) ReadBytes() ([]byte, error) { return nil, errors.New("basicflag provider does not support this method") } - -// Watch is not supported. -func (p *Pflag) Watch(cb func(event interface{}, err error)) error { - return errors.New("basicflag provider does not support this method") -} diff --git a/providers/confmap/confmap.go b/providers/confmap/confmap.go index a151a70..9c5871a 100644 --- a/providers/confmap/confmap.go +++ b/providers/confmap/confmap.go @@ -35,8 +35,3 @@ func (e *Confmap) ReadBytes() ([]byte, error) { func (e *Confmap) Read() (map[string]interface{}, error) { return e.mp, nil } - -// Watch is not supported. -func (e *Confmap) Watch(cb func(event interface{}, err error)) error { - return errors.New("confmap provider does not support this method") -} diff --git a/providers/env/env.go b/providers/env/env.go index 81510b1..5ec252b 100644 --- a/providers/env/env.go +++ b/providers/env/env.go @@ -96,8 +96,3 @@ func (e *Env) Read() (map[string]interface{}, error) { return maps.Unflatten(mp, e.delim), nil } - -// Watch is not supported. -func (e *Env) Watch(cb func(event interface{}, err error)) error { - return errors.New("env provider does not support this method") -} diff --git a/providers/fs/fs.go b/providers/fs/fs.go index 99aa1e6..c008b42 100644 --- a/providers/fs/fs.go +++ b/providers/fs/fs.go @@ -2,6 +2,7 @@ // from given fs.FS to be used with a koanf.Parser to parse // into conf maps. +//go:build go1.16 // +build go1.16 package fs @@ -38,8 +39,3 @@ func (f *FS) ReadBytes() ([]byte, error) { func (f *FS) Read() (map[string]interface{}, error) { return nil, errors.New("fs.FS provider does not support this method") } - -// Watch is not supported by the fs.FS provider. -func (f *FS) Watch(cb func(event interface{}, err error)) error { - return errors.New("fs.FS provider does not support this method") -} diff --git a/providers/rawbytes/rawbytes.go b/providers/rawbytes/rawbytes.go index 3a7242b..96cc0b8 100644 --- a/providers/rawbytes/rawbytes.go +++ b/providers/rawbytes/rawbytes.go @@ -29,8 +29,3 @@ func (r *RawBytes) ReadBytes() ([]byte, error) { func (r *RawBytes) Read() (map[string]interface{}, error) { return nil, errors.New("buf provider does not support this method") } - -// Watch is not supported. -func (r *RawBytes) Watch(cb func(event interface{}, err error)) error { - return errors.New("rawbytes provider does not support this method") -} diff --git a/providers/s3/s3.go b/providers/s3/s3.go index a7fd30b..0088283 100644 --- a/providers/s3/s3.go +++ b/providers/s3/s3.go @@ -68,8 +68,3 @@ func (r *S3) ReadBytes() ([]byte, error) { func (r *S3) Read() (map[string]interface{}, error) { return nil, errors.New("s3 provider does not support this method") } - -// Watch is not supported. -func (r *S3) Watch(cb func(event interface{}, err error)) error { - return errors.New("s3 provider does not support this method") -} diff --git a/providers/structs/structs.go b/providers/structs/structs.go index 78c2a6b..bff92b7 100644 --- a/providers/structs/structs.go +++ b/providers/structs/structs.go @@ -46,8 +46,3 @@ func (s *Structs) Read() (map[string]interface{}, error) { return out, nil } - -// Watch is not supported by the structs provider. -func (s *Structs) Watch(cb func(event interface{}, err error)) error { - return errors.New("structs provider does not support this method") -}