mirror of
https://github.com/spf13/viper
synced 2025-05-06 20:27:17 +00:00
removed dependency to crypt from viper.go
This commit is contained in:
parent
b912d8b835
commit
8cf063907b
2 changed files with 30 additions and 5 deletions
|
@ -40,13 +40,34 @@ func (rc remoteConfigProvider) Watch(rp viper.RemoteProvider) (io.Reader, error)
|
||||||
|
|
||||||
return bytes.NewReader(resp), nil
|
return bytes.NewReader(resp), nil
|
||||||
}
|
}
|
||||||
func (rc remoteConfigProvider) WatchChannel(rp viper.RemoteProvider) (<-chan *crypt.Response, chan bool) {
|
func (rc remoteConfigProvider) WatchChannel(rp viper.RemoteProvider) (<-chan *viper.Response, chan bool) {
|
||||||
cm, err := getConfigManager(rp)
|
cm, err := getConfigManager(rp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
quit := make(chan bool)
|
quit := make(chan bool)
|
||||||
return cm.Watch(rp.Path(), quit) ,quit
|
quitwc := make(chan bool)
|
||||||
|
viperResponsCh := make(chan *viper.Response)
|
||||||
|
cryptoResponseCh := cm.Watch(rp.Path(), quit)
|
||||||
|
// need this function to convert the Channel response form crypt.Response to viper.Response
|
||||||
|
go func(cr <-chan *crypt.Response,vr chan<- *viper.Response, quitwc <-chan bool, quit chan<- bool) {
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <- quitwc:
|
||||||
|
quit <- true
|
||||||
|
return
|
||||||
|
case resp := <-cr:
|
||||||
|
vr <- &viper.Response{
|
||||||
|
Error: resp.Error,
|
||||||
|
Value: resp.Value,
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}(cryptoResponseCh,viperResponsCh,quitwc,quit)
|
||||||
|
|
||||||
|
return viperResponsCh,quitwc
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
10
viper.go
10
viper.go
|
@ -36,11 +36,15 @@ import (
|
||||||
"github.com/spf13/cast"
|
"github.com/spf13/cast"
|
||||||
jww "github.com/spf13/jwalterweatherman"
|
jww "github.com/spf13/jwalterweatherman"
|
||||||
"github.com/spf13/pflag"
|
"github.com/spf13/pflag"
|
||||||
crypt "github.com/xordataexchange/crypt/config"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var v *Viper
|
var v *Viper
|
||||||
|
|
||||||
|
type Response struct {
|
||||||
|
Value []byte
|
||||||
|
Error error
|
||||||
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
v = New()
|
v = New()
|
||||||
}
|
}
|
||||||
|
@ -48,7 +52,7 @@ func init() {
|
||||||
type remoteConfigFactory interface {
|
type remoteConfigFactory interface {
|
||||||
Get(rp RemoteProvider) (io.Reader, error)
|
Get(rp RemoteProvider) (io.Reader, error)
|
||||||
Watch(rp RemoteProvider) (io.Reader, error)
|
Watch(rp RemoteProvider) (io.Reader, error)
|
||||||
WatchChannel(rp RemoteProvider)(<-chan *crypt.Response, chan bool)
|
WatchChannel(rp RemoteProvider)(<-chan *Response, chan bool)
|
||||||
}
|
}
|
||||||
|
|
||||||
// RemoteConfig is optional, see the remote package
|
// RemoteConfig is optional, see the remote package
|
||||||
|
@ -1309,7 +1313,7 @@ func (v *Viper) watchKeyValueConfigOnChannel() error {
|
||||||
for _, rp := range v.remoteProviders {
|
for _, rp := range v.remoteProviders {
|
||||||
respc, _ := RemoteConfig.WatchChannel(rp)
|
respc, _ := RemoteConfig.WatchChannel(rp)
|
||||||
//Todo: Add quit channel
|
//Todo: Add quit channel
|
||||||
go func(rc <-chan *crypt.Response) {
|
go func(rc <-chan *Response) {
|
||||||
for {
|
for {
|
||||||
b := <-rc
|
b := <-rc
|
||||||
reader := bytes.NewReader(b.Value)
|
reader := bytes.NewReader(b.Value)
|
||||||
|
|
Loading…
Add table
Reference in a new issue