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 /tpl | |
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 'tpl')
-rw-r--r-- | tpl/cast/docshelper.go | 8 | ||||
-rw-r--r-- | tpl/collections/collections_test.go | 4 | ||||
-rw-r--r-- | tpl/data/init_test.go | 4 | ||||
-rw-r--r-- | tpl/data/resources_test.go | 8 | ||||
-rw-r--r-- | tpl/encoding/encoding.go | 3 | ||||
-rw-r--r-- | tpl/hugo/init_test.go | 5 | ||||
-rw-r--r-- | tpl/images/images_test.go | 4 | ||||
-rw-r--r-- | tpl/os/os_test.go | 9 | ||||
-rw-r--r-- | tpl/path/path_test.go | 4 | ||||
-rw-r--r-- | tpl/resources/resources.go | 2 | ||||
-rw-r--r-- | tpl/site/init_test.go | 5 | ||||
-rw-r--r-- | tpl/strings/init_test.go | 5 | ||||
-rw-r--r-- | tpl/strings/strings_test.go | 4 | ||||
-rw-r--r-- | tpl/tplimpl/template_funcs_test.go | 6 | ||||
-rw-r--r-- | tpl/transform/remarshal_test.go | 10 | ||||
-rw-r--r-- | tpl/transform/transform_test.go | 16 | ||||
-rw-r--r-- | tpl/transform/unmarshal_test.go | 9 | ||||
-rw-r--r-- | tpl/urls/init_test.go | 5 | ||||
-rw-r--r-- | tpl/urls/urls_test.go | 5 |
19 files changed, 62 insertions, 54 deletions
diff --git a/tpl/cast/docshelper.go b/tpl/cast/docshelper.go index 035db1740..a3cc26de5 100644 --- a/tpl/cast/docshelper.go +++ b/tpl/cast/docshelper.go @@ -15,18 +15,18 @@ package cast import ( "github.com/gohugoio/hugo/common/loggers" + "github.com/gohugoio/hugo/config" "github.com/gohugoio/hugo/deps" "github.com/gohugoio/hugo/docshelper" "github.com/gohugoio/hugo/resources/page" "github.com/gohugoio/hugo/tpl/internal" - "github.com/spf13/viper" ) // This file provides documentation support and is randomly put into this package. func init() { docsProvider := func() docshelper.DocProvider { d := &deps.Deps{ - Cfg: viper.New(), + Cfg: config.New(), Log: loggers.NewErrorLogger(), BuildStartListeners: &deps.Listeners{}, Site: page.NewDummyHugoSite(newTestConfig()), @@ -46,8 +46,8 @@ func init() { docshelper.AddDocProviderFunc(docsProvider) } -func newTestConfig() *viper.Viper { - v := viper.New() +func newTestConfig() config.Provider { + v := config.New() v.Set("contentDir", "content") return v } diff --git a/tpl/collections/collections_test.go b/tpl/collections/collections_test.go index 1e0569751..3faf46930 100644 --- a/tpl/collections/collections_test.go +++ b/tpl/collections/collections_test.go @@ -32,7 +32,7 @@ import ( "github.com/gohugoio/hugo/hugofs" "github.com/gohugoio/hugo/langs" "github.com/spf13/afero" - "github.com/spf13/viper" + ) type tstNoStringer struct{} @@ -986,7 +986,7 @@ func newDeps(cfg config.Provider) *deps.Deps { } func newTestNs() *Namespace { - v := viper.New() + v := config.New() v.Set("contentDir", "content") return New(newDeps(v)) } diff --git a/tpl/data/init_test.go b/tpl/data/init_test.go index fedce8e5c..9174d42a6 100644 --- a/tpl/data/init_test.go +++ b/tpl/data/init_test.go @@ -17,10 +17,10 @@ import ( "testing" qt "github.com/frankban/quicktest" + "github.com/gohugoio/hugo/config" "github.com/gohugoio/hugo/htesting/hqt" "github.com/gohugoio/hugo/langs" "github.com/gohugoio/hugo/tpl/internal" - "github.com/spf13/viper" ) func TestInit(t *testing.T) { @@ -28,7 +28,7 @@ func TestInit(t *testing.T) { var found bool var ns *internal.TemplateFuncsNamespace - v := viper.New() + v := config.New() v.Set("contentDir", "content") langs.LoadLanguageSettings(v, nil) diff --git a/tpl/data/resources_test.go b/tpl/data/resources_test.go index 18061c052..1bf6d769f 100644 --- a/tpl/data/resources_test.go +++ b/tpl/data/resources_test.go @@ -34,12 +34,12 @@ import ( "github.com/gohugoio/hugo/hugofs" "github.com/gohugoio/hugo/langs" "github.com/spf13/afero" - "github.com/spf13/viper" + ) func TestScpGetLocal(t *testing.T) { t.Parallel() - v := viper.New() + v := config.New() fs := hugofs.NewMem(v) ps := helpers.FilePathSeparator @@ -144,7 +144,7 @@ func TestScpGetRemoteParallel(t *testing.T) { c.Assert(err, qt.IsNil) for _, ignoreCache := range []bool{false} { - cfg := viper.New() + cfg := config.New() cfg.Set("ignoreCache", ignoreCache) cfg.Set("contentDir", "content") @@ -223,7 +223,7 @@ func newDeps(cfg config.Provider) *deps.Deps { } func newTestNs() *Namespace { - v := viper.New() + v := config.New() v.Set("contentDir", "content") return New(newDeps(v)) } diff --git a/tpl/encoding/encoding.go b/tpl/encoding/encoding.go index 09e2b94bc..ce25151a0 100644 --- a/tpl/encoding/encoding.go +++ b/tpl/encoding/encoding.go @@ -20,6 +20,7 @@ import ( "errors" "html/template" + "github.com/gohugoio/hugo/common/maps" "github.com/spf13/cast" ) @@ -71,7 +72,7 @@ func (ns *Namespace) Jsonify(args ...interface{}) (template.HTML, error) { case 2: var opts map[string]string - opts, err = cast.ToStringMapStringE(args[0]) + opts, err = maps.ToStringMapStringE(args[0]) if err != nil { break } diff --git a/tpl/hugo/init_test.go b/tpl/hugo/init_test.go index c94a883fd..9b1b14be4 100644 --- a/tpl/hugo/init_test.go +++ b/tpl/hugo/init_test.go @@ -16,20 +16,21 @@ package hugo import ( "testing" + "github.com/gohugoio/hugo/config" + "github.com/gohugoio/hugo/htesting/hqt" qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/deps" "github.com/gohugoio/hugo/resources/page" "github.com/gohugoio/hugo/tpl/internal" - "github.com/spf13/viper" ) func TestInit(t *testing.T) { c := qt.New(t) var found bool var ns *internal.TemplateFuncsNamespace - v := viper.New() + v := config.New() v.Set("contentDir", "content") s := page.NewDummyHugoSite(v) diff --git a/tpl/images/images_test.go b/tpl/images/images_test.go index b1b1e1cfd..2a2b79478 100644 --- a/tpl/images/images_test.go +++ b/tpl/images/images_test.go @@ -22,11 +22,11 @@ import ( "testing" qt "github.com/frankban/quicktest" + "github.com/gohugoio/hugo/config" "github.com/gohugoio/hugo/deps" "github.com/gohugoio/hugo/hugofs" "github.com/spf13/afero" "github.com/spf13/cast" - "github.com/spf13/viper" ) type tstNoStringer struct{} @@ -82,7 +82,7 @@ func TestNSConfig(t *testing.T) { t.Parallel() c := qt.New(t) - v := viper.New() + v := config.New() v.Set("workingDir", "/a/b") ns := New(&deps.Deps{Fs: hugofs.NewMem(v)}) diff --git a/tpl/os/os_test.go b/tpl/os/os_test.go index 3adb6f8c2..bbc0d018c 100644 --- a/tpl/os/os_test.go +++ b/tpl/os/os_test.go @@ -17,11 +17,12 @@ import ( "path/filepath" "testing" + "github.com/gohugoio/hugo/config" + qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/deps" "github.com/gohugoio/hugo/hugofs" "github.com/spf13/afero" - "github.com/spf13/viper" ) func TestReadFile(t *testing.T) { @@ -30,7 +31,7 @@ func TestReadFile(t *testing.T) { workingDir := "/home/hugo" - v := viper.New() + v := config.New() v.Set("workingDir", workingDir) // f := newTestFuncsterWithViper(v) @@ -68,7 +69,7 @@ func TestFileExists(t *testing.T) { workingDir := "/home/hugo" - v := viper.New() + v := config.New() v.Set("workingDir", workingDir) ns := New(&deps.Deps{Fs: hugofs.NewMem(v)}) @@ -103,7 +104,7 @@ func TestStat(t *testing.T) { c := qt.New(t) workingDir := "/home/hugo" - v := viper.New() + v := config.New() v.Set("workingDir", workingDir) ns := New(&deps.Deps{Fs: hugofs.NewMem(v)}) diff --git a/tpl/path/path_test.go b/tpl/path/path_test.go index ce453b9a1..dc0761f2f 100644 --- a/tpl/path/path_test.go +++ b/tpl/path/path_test.go @@ -18,11 +18,11 @@ import ( "testing" qt "github.com/frankban/quicktest" + "github.com/gohugoio/hugo/config" "github.com/gohugoio/hugo/deps" - "github.com/spf13/viper" ) -var ns = New(&deps.Deps{Cfg: viper.New()}) +var ns = New(&deps.Deps{Cfg: config.New()}) type tstNoStringer struct{} diff --git a/tpl/resources/resources.go b/tpl/resources/resources.go index da2b4ca3b..850def00e 100644 --- a/tpl/resources/resources.go +++ b/tpl/resources/resources.go @@ -282,7 +282,7 @@ func (ns *Namespace) ToCSS(args ...interface{}) (resource.Resource, error) { } if m != nil { - maps.ToLower(m) + maps.PrepareParams(m) if t, found := m["transpiler"]; found { switch t { case transpilerDart, transpilerLibSass: diff --git a/tpl/site/init_test.go b/tpl/site/init_test.go index f4a7935ad..f4c2ecd5c 100644 --- a/tpl/site/init_test.go +++ b/tpl/site/init_test.go @@ -16,12 +16,13 @@ package site import ( "testing" + "github.com/gohugoio/hugo/config" + qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/deps" "github.com/gohugoio/hugo/htesting/hqt" "github.com/gohugoio/hugo/resources/page" "github.com/gohugoio/hugo/tpl/internal" - "github.com/spf13/viper" ) func TestInit(t *testing.T) { @@ -29,7 +30,7 @@ func TestInit(t *testing.T) { var found bool var ns *internal.TemplateFuncsNamespace - v := viper.New() + v := config.New() v.Set("contentDir", "content") s := page.NewDummyHugoSite(v) diff --git a/tpl/strings/init_test.go b/tpl/strings/init_test.go index b356896cf..dd15418c8 100644 --- a/tpl/strings/init_test.go +++ b/tpl/strings/init_test.go @@ -16,12 +16,13 @@ package strings import ( "testing" + "github.com/gohugoio/hugo/config" + "github.com/gohugoio/hugo/htesting/hqt" qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/deps" "github.com/gohugoio/hugo/tpl/internal" - "github.com/spf13/viper" ) func TestInit(t *testing.T) { @@ -30,7 +31,7 @@ func TestInit(t *testing.T) { var ns *internal.TemplateFuncsNamespace for _, nsf := range internal.TemplateFuncsNamespaceRegistry { - ns = nsf(&deps.Deps{Cfg: viper.New()}) + ns = nsf(&deps.Deps{Cfg: config.New()}) if ns.Name == name { found = true break diff --git a/tpl/strings/strings_test.go b/tpl/strings/strings_test.go index 6e14a408c..18c033793 100644 --- a/tpl/strings/strings_test.go +++ b/tpl/strings/strings_test.go @@ -17,14 +17,14 @@ import ( "html/template" "testing" + "github.com/gohugoio/hugo/config" "github.com/gohugoio/hugo/deps" qt "github.com/frankban/quicktest" "github.com/spf13/cast" - "github.com/spf13/viper" ) -var ns = New(&deps.Deps{Cfg: viper.New()}) +var ns = New(&deps.Deps{Cfg: config.New()}) type tstNoStringer struct{} diff --git a/tpl/tplimpl/template_funcs_test.go b/tpl/tplimpl/template_funcs_test.go index 67e957924..6ddf13b76 100644 --- a/tpl/tplimpl/template_funcs_test.go +++ b/tpl/tplimpl/template_funcs_test.go @@ -37,13 +37,13 @@ import ( "github.com/gohugoio/hugo/tpl/internal" "github.com/gohugoio/hugo/tpl/partials" "github.com/spf13/afero" - "github.com/spf13/viper" + ) var logger = loggers.NewErrorLogger() func newTestConfig() config.Provider { - v := viper.New() + v := config.New() v.Set("contentDir", "content") v.Set("dataDir", "data") v.Set("i18nDir", "i18n") @@ -206,7 +206,7 @@ func BenchmarkPartialCached(b *testing.B) { func doBenchmarkPartial(b *testing.B, f func(ns *partials.Namespace) error) { c := qt.New(b) - config := newDepsConfig(viper.New()) + config := newDepsConfig(config.New()) config.WithTemplate = func(templ tpl.TemplateManager) error { err := templ.AddTemplate("partials/bench1", `{{ shuffle (seq 1 10) }}`) if err != nil { diff --git a/tpl/transform/remarshal_test.go b/tpl/transform/remarshal_test.go index eb5f4253c..9f3e05e61 100644 --- a/tpl/transform/remarshal_test.go +++ b/tpl/transform/remarshal_test.go @@ -16,16 +16,16 @@ package transform import ( "testing" + "github.com/gohugoio/hugo/config" "github.com/gohugoio/hugo/htesting" qt "github.com/frankban/quicktest" - "github.com/spf13/viper" ) func TestRemarshal(t *testing.T) { t.Parallel() - v := viper.New() + v := config.New() v.Set("contentDir", "content") ns := New(newDeps(v)) c := qt.New(t) @@ -112,7 +112,7 @@ title: Test Metadata func TestRemarshalComments(t *testing.T) { t.Parallel() - v := viper.New() + v := config.New() v.Set("contentDir", "content") ns := New(newDeps(v)) @@ -158,7 +158,7 @@ func TestTestRemarshalError(t *testing.T) { t.Parallel() c := qt.New(t) - v := viper.New() + v := config.New() v.Set("contentDir", "content") ns := New(newDeps(v)) @@ -172,7 +172,7 @@ func TestTestRemarshalError(t *testing.T) { func TestTestRemarshalMapInput(t *testing.T) { t.Parallel() c := qt.New(t) - v := viper.New() + v := config.New() v.Set("contentDir", "content") ns := New(newDeps(v)) diff --git a/tpl/transform/transform_test.go b/tpl/transform/transform_test.go index b98d82d27..1dbf97f98 100644 --- a/tpl/transform/transform_test.go +++ b/tpl/transform/transform_test.go @@ -26,7 +26,7 @@ import ( "github.com/gohugoio/hugo/helpers" "github.com/gohugoio/hugo/hugofs" "github.com/gohugoio/hugo/langs" - "github.com/spf13/viper" + ) type tstNoStringer struct{} @@ -35,7 +35,7 @@ func TestEmojify(t *testing.T) { t.Parallel() c := qt.New(t) - v := viper.New() + v := config.New() ns := New(newDeps(v)) for _, test := range []struct { @@ -64,7 +64,7 @@ func TestHighlight(t *testing.T) { t.Parallel() c := qt.New(t) - v := viper.New() + v := config.New() v.Set("contentDir", "content") ns := New(newDeps(v)) @@ -96,7 +96,7 @@ func TestHTMLEscape(t *testing.T) { t.Parallel() c := qt.New(t) - v := viper.New() + v := config.New() v.Set("contentDir", "content") ns := New(newDeps(v)) @@ -126,7 +126,7 @@ func TestHTMLUnescape(t *testing.T) { t.Parallel() c := qt.New(t) - v := viper.New() + v := config.New() v.Set("contentDir", "content") ns := New(newDeps(v)) @@ -156,7 +156,7 @@ func TestMarkdownify(t *testing.T) { t.Parallel() c := qt.New(t) - v := viper.New() + v := config.New() v.Set("contentDir", "content") ns := New(newDeps(v)) @@ -185,7 +185,7 @@ func TestMarkdownify(t *testing.T) { func TestMarkdownifyBlocksOfText(t *testing.T) { t.Parallel() c := qt.New(t) - v := viper.New() + v := config.New() v.Set("contentDir", "content") ns := New(newDeps(v)) @@ -211,7 +211,7 @@ func TestPlainify(t *testing.T) { t.Parallel() c := qt.New(t) - v := viper.New() + v := config.New() ns := New(newDeps(v)) for _, test := range []struct { diff --git a/tpl/transform/unmarshal_test.go b/tpl/transform/unmarshal_test.go index ec81c316a..85e3610d1 100644 --- a/tpl/transform/unmarshal_test.go +++ b/tpl/transform/unmarshal_test.go @@ -19,13 +19,14 @@ import ( "strings" "testing" + "github.com/gohugoio/hugo/config" + "github.com/gohugoio/hugo/common/hugio" "github.com/gohugoio/hugo/resources/resource" "github.com/gohugoio/hugo/media" qt "github.com/frankban/quicktest" - "github.com/spf13/viper" ) const ( @@ -79,7 +80,7 @@ func (t testContentResource) Key() string { } func TestUnmarshal(t *testing.T) { - v := viper.New() + v := config.New() ns := New(newDeps(v)) c := qt.New(t) @@ -173,7 +174,7 @@ a;b;c`, mime: media.CSVType}, map[string]interface{}{"DElimiter": ";", "Comment" } func BenchmarkUnmarshalString(b *testing.B) { - v := viper.New() + v := config.New() ns := New(newDeps(v)) const numJsons = 100 @@ -196,7 +197,7 @@ func BenchmarkUnmarshalString(b *testing.B) { } func BenchmarkUnmarshalResource(b *testing.B) { - v := viper.New() + v := config.New() ns := New(newDeps(v)) const numJsons = 100 diff --git a/tpl/urls/init_test.go b/tpl/urls/init_test.go index f88aaf398..27b21144a 100644 --- a/tpl/urls/init_test.go +++ b/tpl/urls/init_test.go @@ -16,11 +16,12 @@ package urls import ( "testing" + "github.com/gohugoio/hugo/config" + qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/deps" "github.com/gohugoio/hugo/htesting/hqt" "github.com/gohugoio/hugo/tpl/internal" - "github.com/spf13/viper" ) func TestInit(t *testing.T) { @@ -29,7 +30,7 @@ func TestInit(t *testing.T) { var ns *internal.TemplateFuncsNamespace for _, nsf := range internal.TemplateFuncsNamespaceRegistry { - ns = nsf(&deps.Deps{Cfg: viper.New()}) + ns = nsf(&deps.Deps{Cfg: config.New()}) if ns.Name == name { found = true break diff --git a/tpl/urls/urls_test.go b/tpl/urls/urls_test.go index 9c005d2df..23068c243 100644 --- a/tpl/urls/urls_test.go +++ b/tpl/urls/urls_test.go @@ -17,14 +17,15 @@ import ( "net/url" "testing" + "github.com/gohugoio/hugo/config" + "github.com/gohugoio/hugo/htesting/hqt" qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/deps" - "github.com/spf13/viper" ) -var ns = New(&deps.Deps{Cfg: viper.New()}) +var ns = New(&deps.Deps{Cfg: config.New()}) type tstNoStringer struct{} |