spf13 / viper

Go configuration with fangs
MIT License
27.01k stars 2.01k forks source link

ReadRemoteConfig is the same with WatchRemoteConfig ? #420

Open zoumo opened 6 years ago

zoumo commented 6 years ago

After reading the source code, I found that viper.ReadRemoteConfig is the same with viper.WatchRemoteConfig.

viper.ReadRemoteConfig invokes RemoteConfig.Get, in remote/remote.go

func (rc remoteConfigProvider) Get(rp viper.RemoteProvider) (io.Reader, error) {
    cm, err := getConfigManager(rp)
    if err != nil {
        return nil, err
    }
    b, err := cm.Get(rp.Path())
    if err != nil {
        return nil, err
    }
    return bytes.NewReader(b), nil
}

viper.WatchRemoteConfig invokes RemoteConfig.Watch, in remote/remote.go

func (rc remoteConfigProvider) Watch(rp viper.RemoteProvider) (io.Reader, error) {
    cm, err := getConfigManager(rp)
    if err != nil {
        return nil, err
    }
    resp, err := cm.Get(rp.Path())
    if err != nil {
        return nil, err
    }

    return bytes.NewReader(resp), nil
}

Obviously, they are exactly the same. What's the purpose?

zoumo commented 6 years ago

@spf13 @bep