mirror of
https://github.com/spf13/viper
synced 2024-12-23 03:57:01 +00:00
replace bytes.Buffer with io.Reader
This commit is contained in:
parent
9c9f7f12c8
commit
5736fabdfa
2 changed files with 11 additions and 4 deletions
13
viper.go
13
viper.go
|
@ -716,13 +716,20 @@ func (v *Viper) ReadInConfig() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func ReadBufConfig(buf *bytes.Buffer) error { return v.ReadBufConfig(buf) }
|
func ReadConfig(in io.Reader) error { return v.ReadConfig(in) }
|
||||||
func (v *Viper) ReadBufConfig(buf *bytes.Buffer) error {
|
func (v *Viper) ReadConfig(in io.Reader) error {
|
||||||
v.config = make(map[string]interface{})
|
v.config = make(map[string]interface{})
|
||||||
v.marshalReader(buf, v.config)
|
v.marshalReader(in, v.config)
|
||||||
return nil
|
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
|
// Attempts to get configuration from a remote source
|
||||||
// and read it in the remote configuration registry.
|
// and read it in the remote configuration registry.
|
||||||
func ReadRemoteConfig() error { return v.ReadRemoteConfig() }
|
func ReadRemoteConfig() error { return v.ReadRemoteConfig() }
|
||||||
|
|
|
@ -541,7 +541,7 @@ func TestFindsNestedKeys(t *testing.T) {
|
||||||
func TestReadBufConfig(t *testing.T) {
|
func TestReadBufConfig(t *testing.T) {
|
||||||
v := New()
|
v := New()
|
||||||
v.SetConfigType("yaml")
|
v.SetConfigType("yaml")
|
||||||
v.ReadBufConfig(bytes.NewBuffer(yamlExample))
|
v.ReadConfig(bytes.NewBuffer(yamlExample))
|
||||||
t.Log(v.AllKeys())
|
t.Log(v.AllKeys())
|
||||||
|
|
||||||
assert.True(t, v.InConfig("name"))
|
assert.True(t, v.InConfig("name"))
|
||||||
|
|
Loading…
Reference in a new issue