From 0b5690fd875739811249ca79d24afd8f89f188c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Wed, 15 Mar 2017 08:09:33 +0100 Subject: [PATCH] Revert "remote: Avoid the start of go-routines which are never get stopped" This reverts commit 11ca61e88892f9cb3cff255826cb7ace534d340d. --- remote/remote.go | 15 +++------------ viper.go | 23 ----------------------- 2 files changed, 3 insertions(+), 35 deletions(-) diff --git a/remote/remote.go b/remote/remote.go index f36f035..faaf3b3 100644 --- a/remote/remote.go +++ b/remote/remote.go @@ -33,23 +33,14 @@ func (rc remoteConfigProvider) Watch(rp viper.RemoteProvider) (io.Reader, error) if err != nil { return nil, err } - resp,err := cm.Get(rp.Path()) + resp := <-cm.Watch(rp.Path(), nil) + err = resp.Error if err != nil { return nil, err } - return bytes.NewReader(resp), nil + return bytes.NewReader(resp.Value), nil } -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) - return cm.Watch(rp.Path(), quit) ,quit - -} - func getConfigManager(rp viper.RemoteProvider) (crypt.ConfigManager, error) { diff --git a/viper.go b/viper.go index 56278f3..fce13b1 100644 --- a/viper.go +++ b/viper.go @@ -36,7 +36,6 @@ import ( "github.com/spf13/cast" jww "github.com/spf13/jwalterweatherman" "github.com/spf13/pflag" - crypt "github.com/xordataexchange/crypt/config" ) var v *Viper @@ -48,7 +47,6 @@ func init() { type remoteConfigFactory interface { Get(rp RemoteProvider) (io.Reader, error) Watch(rp RemoteProvider) (io.Reader, error) - WatchChannel(rp RemoteProvider)(<-chan *crypt.Response, chan bool) } // RemoteConfig is optional, see the remote package @@ -1257,10 +1255,6 @@ func (v *Viper) WatchRemoteConfig() error { return v.watchKeyValueConfig() } -func (v *Viper) WatchRemoteConfigOnChannel() error { - return v.watchKeyValueConfigOnChannel() -} - // Unmarshall a Reader into a map. // Should probably be an unexported function. func unmarshalReader(in io.Reader, c map[string]interface{}) error { @@ -1304,23 +1298,6 @@ func (v *Viper) getRemoteConfig(provider RemoteProvider) (map[string]interface{} return v.kvstore, err } -// Retrieve the first found remote configuration. -func (v *Viper) watchKeyValueConfigOnChannel() error { - for _, rp := range v.remoteProviders { - respc, _ := RemoteConfig.WatchChannel(rp) - //Todo: Add quit channel - go func(rc <-chan *crypt.Response) { - for { - b := <-rc - reader := bytes.NewReader(b.Value) - v.unmarshalReader(reader, v.kvstore) - } - }(respc) - return nil - } - return RemoteConfigError("No Files Found") -} - // Retrieve the first found remote configuration. func (v *Viper) watchKeyValueConfig() error { for _, rp := range v.remoteProviders {