mirror of
https://github.com/spf13/viper
synced 2025-05-06 20:27:17 +00:00
renamed Response to RemoteResponse
This commit is contained in:
parent
8cf063907b
commit
65b703039c
2 changed files with 7 additions and 7 deletions
|
@ -40,24 +40,24 @@ 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 *viper.Response, chan bool) {
|
func (rc remoteConfigProvider) WatchChannel(rp viper.RemoteProvider) (<-chan *viper.RemoteResponse, 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)
|
||||||
quitwc := make(chan bool)
|
quitwc := make(chan bool)
|
||||||
viperResponsCh := make(chan *viper.Response)
|
viperResponsCh := make(chan *viper.RemoteResponse)
|
||||||
cryptoResponseCh := cm.Watch(rp.Path(), quit)
|
cryptoResponseCh := cm.Watch(rp.Path(), quit)
|
||||||
// need this function to convert the Channel response form crypt.Response to viper.Response
|
// 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) {
|
go func(cr <-chan *crypt.Response,vr chan<- *viper.RemoteResponse, quitwc <-chan bool, quit chan<- bool) {
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <- quitwc:
|
case <- quitwc:
|
||||||
quit <- true
|
quit <- true
|
||||||
return
|
return
|
||||||
case resp := <-cr:
|
case resp := <-cr:
|
||||||
vr <- &viper.Response{
|
vr <- &viper.RemoteResponse{
|
||||||
Error: resp.Error,
|
Error: resp.Error,
|
||||||
Value: resp.Value,
|
Value: resp.Value,
|
||||||
}
|
}
|
||||||
|
|
6
viper.go
6
viper.go
|
@ -40,7 +40,7 @@ import (
|
||||||
|
|
||||||
var v *Viper
|
var v *Viper
|
||||||
|
|
||||||
type Response struct {
|
type RemoteResponse struct {
|
||||||
Value []byte
|
Value []byte
|
||||||
Error error
|
Error error
|
||||||
}
|
}
|
||||||
|
@ -52,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 *Response, chan bool)
|
WatchChannel(rp RemoteProvider)(<-chan *RemoteResponse, chan bool)
|
||||||
}
|
}
|
||||||
|
|
||||||
// RemoteConfig is optional, see the remote package
|
// RemoteConfig is optional, see the remote package
|
||||||
|
@ -1313,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 *Response) {
|
go func(rc <-chan *RemoteResponse) {
|
||||||
for {
|
for {
|
||||||
b := <-rc
|
b := <-rc
|
||||||
reader := bytes.NewReader(b.Value)
|
reader := bytes.NewReader(b.Value)
|
||||||
|
|
Loading…
Add table
Reference in a new issue