replace bytes.Buffer with io.Reader

This commit is contained in:
oliveagle 2015-05-14 17:40:59 +08:00 committed by spf13
parent 2a7f7f40fc
commit f3482afcd0
2 changed files with 11 additions and 4 deletions

View File

@ -716,13 +716,20 @@ func (v *Viper) ReadInConfig() error {
return nil
}
func ReadBufConfig(buf *bytes.Buffer) error { return v.ReadBufConfig(buf) }
func (v *Viper) ReadBufConfig(buf *bytes.Buffer) error {
func ReadConfig(in io.Reader) error { return v.ReadConfig(in) }
func (v *Viper) ReadConfig(in io.Reader) error {
v.config = make(map[string]interface{})
v.marshalReader(buf, v.config)
v.marshalReader(in, v.config)
return nil
}
// func ReadBufConfig(buf *bytes.Buffer) error { return v.ReadBufConfig(buf) }
// func (v *Viper) ReadBufConfig(buf *bytes.Buffer) error {
// v.config = make(map[string]interface{})
// v.marshalReader(buf, v.config)
// return nil
// }
// Attempts to get configuration from a remote source
// and read it in the remote configuration registry.
func ReadRemoteConfig() error { return v.ReadRemoteConfig() }

View File

@ -541,7 +541,7 @@ func TestFindsNestedKeys(t *testing.T) {
func TestReadBufConfig(t *testing.T) {
v := New()
v.SetConfigType("yaml")
v.ReadBufConfig(bytes.NewBuffer(yamlExample))
v.ReadConfig(bytes.NewBuffer(yamlExample))
t.Log(v.AllKeys())
assert.True(t, v.InConfig("name"))