mirror of
https://github.com/spf13/viper
synced 2024-12-22 19:47:01 +00:00
Add support for yml extension
This commit is contained in:
parent
1a2e68e1bc
commit
16d5c7c27d
2 changed files with 11 additions and 2 deletions
4
viper.go
4
viper.go
|
@ -223,7 +223,7 @@ func MarshallReader(in io.Reader) {
|
||||||
buf.ReadFrom(in)
|
buf.ReadFrom(in)
|
||||||
|
|
||||||
switch getConfigType() {
|
switch getConfigType() {
|
||||||
case "yaml":
|
case "yaml", "yml":
|
||||||
if err := yaml.Unmarshal(buf.Bytes(), &config); err != nil {
|
if err := yaml.Unmarshal(buf.Bytes(), &config); err != nil {
|
||||||
jww.ERROR.Fatalf("Error parsing config: %s", err)
|
jww.ERROR.Fatalf("Error parsing config: %s", err)
|
||||||
}
|
}
|
||||||
|
@ -399,7 +399,7 @@ func Reset() {
|
||||||
configName = "config"
|
configName = "config"
|
||||||
|
|
||||||
// extensions Supported
|
// extensions Supported
|
||||||
SupportedExts = []string{"json", "toml", "yaml"}
|
SupportedExts = []string{"json", "toml", "yaml", "yml"}
|
||||||
configFile = ""
|
configFile = ""
|
||||||
configType = ""
|
configType = ""
|
||||||
|
|
||||||
|
|
|
@ -83,6 +83,15 @@ func TestAliases(t *testing.T) {
|
||||||
assert.Equal(t, 45, Get("age"))
|
assert.Equal(t, 45, Get("age"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestYML(t *testing.T) {
|
||||||
|
Reset()
|
||||||
|
SetConfigType("yml")
|
||||||
|
r := bytes.NewReader(yamlExample)
|
||||||
|
|
||||||
|
MarshallReader(r)
|
||||||
|
assert.Equal(t, "steve", Get("name"))
|
||||||
|
}
|
||||||
|
|
||||||
func TestJSON(t *testing.T) {
|
func TestJSON(t *testing.T) {
|
||||||
SetConfigType("json")
|
SetConfigType("json")
|
||||||
r := bytes.NewReader(jsonExample)
|
r := bytes.NewReader(jsonExample)
|
||||||
|
|
Loading…
Reference in a new issue