replace bytes.Buffer with io.Reader

This commit is contained in:
oliveagle 2015-05-14 17:40:59 +08:00
parent 9c9f7f12c8
commit 5736fabdfa
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"))