diff --git a/remote/remote.go b/remote/remote.go index ac2183c..f36f035 100644 --- a/remote/remote.go +++ b/remote/remote.go @@ -40,26 +40,13 @@ func (rc remoteConfigProvider) Watch(rp viper.RemoteProvider) (io.Reader, error) return bytes.NewReader(resp), nil } -func (rc remoteConfigProvider) WatchChannel(rp viper.RemoteProvider) (<-chan *viper.RemoteResponse, chan bool) { +func (rc remoteConfigProvider) WatchChannel(rp viper.RemoteProvider) (<-chan *crypt.Response, chan bool) { cm, err := getConfigManager(rp) if err != nil { return nil, nil } quit := make(chan bool) - respChan := make(chan *viper.RemoteResponse, 0) - watchchan := cm.Watch(rp.Path(), quit) - // Todo Add quit channel - go func(w <-chan *crypt.Response) { - for { - resp := <-w - respChan <- &viper.RemoteResponse{ - Error: resp.Error, - Value: resp.Value, - } - } - - }(watchchan) - return respChan ,quit + return cm.Watch(rp.Path(), quit) ,quit } diff --git a/viper.go b/viper.go index 47adc71..56278f3 100644 --- a/viper.go +++ b/viper.go @@ -36,13 +36,9 @@ import ( "github.com/spf13/cast" jww "github.com/spf13/jwalterweatherman" "github.com/spf13/pflag" + crypt "github.com/xordataexchange/crypt/config" ) -// Response represents a response from a backend store. -type RemoteResponse struct { - Value []byte - Error error -} var v *Viper func init() { @@ -52,7 +48,7 @@ func init() { type remoteConfigFactory interface { Get(rp RemoteProvider) (io.Reader, error) Watch(rp RemoteProvider) (io.Reader, error) - WatchChannel(rp RemoteProvider)(<-chan *RemoteResponse, chan bool) + WatchChannel(rp RemoteProvider)(<-chan *crypt.Response, chan bool) } // RemoteConfig is optional, see the remote package @@ -1313,7 +1309,7 @@ func (v *Viper) watchKeyValueConfigOnChannel() error { for _, rp := range v.remoteProviders { respc, _ := RemoteConfig.WatchChannel(rp) //Todo: Add quit channel - go func(rc <-chan *RemoteResponse) { + go func(rc <-chan *crypt.Response) { for { b := <-rc reader := bytes.NewReader(b.Value)