diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2021-06-09 10:58:18 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2021-06-14 17:00:32 +0200 |
commit | d392893cd73dc00c927f342778f6dca9628d328e (patch) | |
tree | e2ea3eec09f36b7122ecdbc498c3c130e240e85c /config/configLoader.go | |
parent | a886dd53b80322e1edf924f2ede4d4ea037c5baf (diff) |
Misc config loading fixes
The main motivation behind this is simplicity and correctnes, but the new small config library is also faster:
```
BenchmarkDefaultConfigProvider/Viper-16 252418 4546 ns/op 2720 B/op 30 allocs/op
BenchmarkDefaultConfigProvider/Custom-16 450756 2651 ns/op 1008 B/op 6 allocs/op
```
Fixes #8633
Fixes #8618
Fixes #8630
Updates #8591
Closes #6680
Closes #5192
Diffstat (limited to 'config/configLoader.go')
-rw-r--r-- | config/configLoader.go | 23 |
1 files changed, 2 insertions, 21 deletions
diff --git a/config/configLoader.go b/config/configLoader.go index 6d94f0b79..0998b1bef 100644 --- a/config/configLoader.go +++ b/config/configLoader.go @@ -20,7 +20,6 @@ import ( "github.com/gohugoio/hugo/common/maps" "github.com/gohugoio/hugo/parser/metadecoders" "github.com/spf13/afero" - "github.com/spf13/viper" ) var ( @@ -43,15 +42,11 @@ func IsValidConfigFilename(filename string) bool { // FromConfigString creates a config from the given YAML, JSON or TOML config. This is useful in tests. func FromConfigString(config, configType string) (Provider, error) { - v := newViper() m, err := readConfig(metadecoders.FormatFromString(configType), []byte(config)) if err != nil { return nil, err } - - v.MergeConfigMap(m) - - return v, nil + return NewFrom(m), nil } // FromFile loads the configuration from the given filename. @@ -60,15 +55,7 @@ func FromFile(fs afero.Fs, filename string) (Provider, error) { if err != nil { return nil, err } - - v := newViper() - - err = v.MergeConfigMap(m) - if err != nil { - return nil, err - } - - return v, nil + return NewFrom(m), nil } // FromFileToMap is the same as FromFile, but it returns the config values @@ -116,9 +103,3 @@ func init() { func RenameKeys(m map[string]interface{}) { keyAliases.Rename(m) } - -func newViper() *viper.Viper { - v := viper.New() - - return v -} |