MCPcopy
hub / github.com/spf13/viper / WatchChannel

Method WatchChannel

remote/remote.go:47–73  ·  view source on GitHub ↗
(rp viper.RemoteProvider)

Source from the content-addressed store, hash-verified

45}
46
47func (rc remoteConfigProvider) WatchChannel(rp viper.RemoteProvider) (<-chan *viper.RemoteResponse, chan bool) {
48 cm, err := getConfigManager(rp)
49 if err != nil {
50 return nil, nil
51 }
52 quit := make(chan bool)
53 quitwc := make(chan bool)
54 viperResponsCh := make(chan *viper.RemoteResponse)
55 cryptoResponseCh := cm.Watch(rp.Path(), quit)
56 // need this function to convert the Channel response form crypt.Response to viper.Response
57 go func(cr <-chan *crypt.Response, vr chan<- *viper.RemoteResponse, quitwc <-chan bool, quit chan<- bool) {
58 for {
59 select {
60 case <-quitwc:
61 quit <- true
62 return
63 case resp := <-cr:
64 vr <- &viper.RemoteResponse{
65 Error: resp.Error,
66 Value: resp.Value,
67 }
68 }
69 }
70 }(cryptoResponseCh, viperResponsCh, quitwc, quit)
71
72 return viperResponsCh, quitwc
73}
74
75func getConfigManager(rp viper.RemoteProvider) (crypt.ConfigManager, error) {
76 var cm crypt.ConfigManager

Callers

nothing calls this directly

Calls 3

getConfigManagerFunction · 0.85
WatchMethod · 0.65
PathMethod · 0.65

Tested by

no test coverage detected