diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2022-03-17 22:03:27 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2022-03-17 22:03:27 +0100 |
commit | b80853de90b10171155b8f3fde47d64ec7bfa0dd (patch) | |
tree | 435d3dbf7a495a0c6ce64c9769e037179aa0d27b /hugolib | |
parent | 423594e03a906ef4150f433666ff588b022c3c92 (diff) |
all: gofmt -w -r 'interface{} -> any' .
Updates #9687
Diffstat (limited to 'hugolib')
41 files changed, 337 insertions, 337 deletions
diff --git a/hugolib/alias_test.go b/hugolib/alias_test.go index 8c00f8360..124c9f4ca 100644 --- a/hugolib/alias_test.go +++ b/hugolib/alias_test.go @@ -51,13 +51,13 @@ func TestAlias(t *testing.T) { fileSuffix string urlPrefix string urlSuffix string - settings map[string]interface{} + settings map[string]any }{ - {"/index.html", "http://example.com", "/", map[string]interface{}{"baseURL": "http://example.com"}}, - {"/index.html", "http://example.com/some/path", "/", map[string]interface{}{"baseURL": "http://example.com/some/path"}}, - {"/index.html", "http://example.com", "/", map[string]interface{}{"baseURL": "http://example.com", "canonifyURLs": true}}, - {"/index.html", "../..", "/", map[string]interface{}{"relativeURLs": true}}, - {".html", "", ".html", map[string]interface{}{"uglyURLs": true}}, + {"/index.html", "http://example.com", "/", map[string]any{"baseURL": "http://example.com"}}, + {"/index.html", "http://example.com/some/path", "/", map[string]any{"baseURL": "http://example.com/some/path"}}, + {"/index.html", "http://example.com", "/", map[string]any{"baseURL": "http://example.com", "canonifyURLs": true}}, + {"/index.html", "../..", "/", map[string]any{"relativeURLs": true}}, + {".html", "", ".html", map[string]any{"uglyURLs": true}}, } for _, test := range tests { diff --git a/hugolib/cascade_test.go b/hugolib/cascade_test.go index b7ca45290..c218aa282 100644 --- a/hugolib/cascade_test.go +++ b/hugolib/cascade_test.go @@ -335,7 +335,7 @@ Banner: post.jpg`, } func newCascadeTestBuilder(t testing.TB, langs []string) *sitesBuilder { - p := func(m map[string]interface{}) string { + p := func(m map[string]any) string { var yamlStr string if len(m) > 0 { @@ -392,76 +392,76 @@ defaultContentLanguageInSubDir = false } withContent( - "_index.md", p(map[string]interface{}{ + "_index.md", p(map[string]any{ "title": "Home", - "cascade": map[string]interface{}{ + "cascade": map[string]any{ "title": "Cascade Home", "ICoN": "home.png", "outputs": []string{"HTML"}, "weight": 42, }, }), - "p1.md", p(map[string]interface{}{ + "p1.md", p(map[string]any{ "title": "p1", }), - "p2.md", p(map[string]interface{}{}), - "sect1/_index.md", p(map[string]interface{}{ + "p2.md", p(map[string]any{}), + "sect1/_index.md", p(map[string]any{ "title": "Sect1", "type": "stype", - "cascade": map[string]interface{}{ + "cascade": map[string]any{ "title": "Cascade Sect1", "icon": "sect1.png", "type": "stype", "categories": []string{"catsect1"}, }, }), - "sect1/s1_2/_index.md", p(map[string]interface{}{ + "sect1/s1_2/_index.md", p(map[string]any{ "title": "Sect1_2", }), - "sect1/s1_2/p1.md", p(map[string]interface{}{ + "sect1/s1_2/p1.md", p(map[string]any{ "title": "Sect1_2_p1", }), - "sect1/s1_2/p2.md", p(map[string]interface{}{ + "sect1/s1_2/p2.md", p(map[string]any{ "title": "Sect1_2_p2", }), - "sect2/_index.md", p(map[string]interface{}{ + "sect2/_index.md", p(map[string]any{ "title": "Sect2", }), - "sect2/p1.md", p(map[string]interface{}{ + "sect2/p1.md", p(map[string]any{ "title": "Sect2_p1", "categories": []string{"cool", "funny", "sad"}, "tags": []string{"blue", "green"}, }), - "sect2/p2.md", p(map[string]interface{}{}), - "sect3/p1.md", p(map[string]interface{}{}), + "sect2/p2.md", p(map[string]any{}), + "sect3/p1.md", p(map[string]any{}), // No front matter, see #6855 "sect3/nofrontmatter.md", `**Hello**`, "sectnocontent/p1.md", `**Hello**`, "sectnofrontmatter/_index.md", `**Hello**`, - "sect4/_index.md", p(map[string]interface{}{ + "sect4/_index.md", p(map[string]any{ "title": "Sect4", - "cascade": map[string]interface{}{ + "cascade": map[string]any{ "weight": 52, "outputs": []string{"RSS"}, }, }), - "sect4/p1.md", p(map[string]interface{}{}), - "p2.md", p(map[string]interface{}{}), - "bundle1/index.md", p(map[string]interface{}{}), - "bundle1/bp1.md", p(map[string]interface{}{}), - "categories/_index.md", p(map[string]interface{}{ + "sect4/p1.md", p(map[string]any{}), + "p2.md", p(map[string]any{}), + "bundle1/index.md", p(map[string]any{}), + "bundle1/bp1.md", p(map[string]any{}), + "categories/_index.md", p(map[string]any{ "title": "My Categories", - "cascade": map[string]interface{}{ + "cascade": map[string]any{ "title": "Cascade Category", "icoN": "cat.png", "weight": 12, }, }), - "categories/cool/_index.md", p(map[string]interface{}{}), - "categories/sad/_index.md", p(map[string]interface{}{ - "cascade": map[string]interface{}{ + "categories/cool/_index.md", p(map[string]any{}), + "categories/sad/_index.md", p(map[string]any{ + "cascade": map[string]any{ "icon": "sad.png", "weight": 32, }, diff --git a/hugolib/collections.go b/hugolib/collections.go index 9b4f83cc6..933f7dadc 100644 --- a/hugolib/collections.go +++ b/hugolib/collections.go @@ -28,7 +28,7 @@ var ( // implementations have no value on their own. // Slice is not meant to be used externally. It's a bridge function -func (p *pageState) Slice(items interface{}) (interface{}, error) { +func (p *pageState) Slice(items any) (any, error) { return page.ToPages(items) } @@ -37,7 +37,7 @@ func (p *pageState) Slice(items interface{}) (interface{}, error) { // Group creates a PageGroup from a key and a Pages object // This method is not meant for external use. It got its non-typed arguments to satisfy // a very generic interface in the tpl package. -func (p *pageState) Group(key interface{}, in interface{}) (interface{}, error) { +func (p *pageState) Group(key any, in any) (any, error) { pages, err := page.ToPages(in) if err != nil { return nil, err diff --git a/hugolib/config_test.go b/hugolib/config_test.go index bbf821232..222568b7c 100644 --- a/hugolib/config_test.go +++ b/hugolib/config_test.go @@ -250,12 +250,12 @@ name = "menu-theme" b.Assert(got["mediatypes"], qt.DeepEquals, maps.Params{ "text/m2": maps.Params{ - "suffixes": []interface{}{ + "suffixes": []any{ "m2theme", }, }, "text/m1": maps.Params{ - "suffixes": []interface{}{ + "suffixes": []any{ "m1main", }, }, @@ -293,13 +293,13 @@ name = "menu-theme" "pl1": "p1-en-main", }, "menus": maps.Params{ - "main": []interface{}{ - map[string]interface{}{ + "main": []any{ + map[string]any{ "name": "menu-lang-en-main", }, }, - "theme": []interface{}{ - map[string]interface{}{ + "theme": []any{ + map[string]any{ "name": "menu-lang-en-theme", }, }, @@ -313,18 +313,18 @@ name = "menu-theme" "pl2": "p2-nb-theme", }, "menus": maps.Params{ - "main": []interface{}{ - map[string]interface{}{ + "main": []any{ + map[string]any{ "name": "menu-lang-nb-main", }, }, - "theme": []interface{}{ - map[string]interface{}{ + "theme": []any{ + map[string]any{ "name": "menu-lang-nb-theme", }, }, - "top": []interface{}{ - map[string]interface{}{ + "top": []any{ + map[string]any{ "name": "menu-lang-nb-top", }, }, @@ -399,8 +399,8 @@ name = "menu-theme" "en": maps.Params{ "languagename": "English", "menus": maps.Params{ - "main": []interface{}{ - map[string]interface{}{ + "main": []any{ + map[string]any{ "name": "menu-theme", }, }, @@ -710,9 +710,9 @@ theme_param="themevalue2" c.Assert(cfg.Get("imaging.anchor"), qt.Equals, "top") c.Assert(cfg.Get("imaging.quality"), qt.Equals, int64(75)) c.Assert(cfg.Get("imaging.resamplefilter"), qt.Equals, "CatmullRom") - c.Assert(cfg.Get("stringSlice"), qt.DeepEquals, []interface{}{"c", "d"}) - c.Assert(cfg.Get("floatSlice"), qt.DeepEquals, []interface{}{5.32}) - c.Assert(cfg.Get("intSlice"), qt.DeepEquals, []interface{}{5, 8, 9}) + c.Assert(cfg.Get("stringSlice"), qt.DeepEquals, []any{"c", "d"}) + c.Assert(cfg.Get("floatSlice"), qt.DeepEquals, []any{5.32}) + c.Assert(cfg.Get("intSlice"), qt.DeepEquals, []any{5, 8, 9}) c.Assert(cfg.Get("params.api_config.api_key"), qt.Equals, "new_key") c.Assert(cfg.Get("params.api_config.another_key"), qt.Equals, "default another_key") c.Assert(cfg.Get("params.mytheme_section.theme_param"), qt.Equals, "themevalue_changed") diff --git a/hugolib/configdir_test.go b/hugolib/configdir_test.go index b3fc71e58..998010318 100644 --- a/hugolib/configdir_test.go +++ b/hugolib/configdir_test.go @@ -119,10 +119,10 @@ p3 = "p3params_no_production" c.Assert(cfg.GetString("params.p3"), qt.Equals, "p3params_development") c.Assert(cfg.GetString("languages.no.params.p3"), qt.Equals, "p3params_no_development") - c.Assert(len(cfg.Get("menus.docs").([]interface{})), qt.Equals, 2) + c.Assert(len(cfg.Get("menus.docs").([]any)), qt.Equals, 2) noMenus := cfg.Get("languages.no.menus.docs") c.Assert(noMenus, qt.Not(qt.IsNil)) - c.Assert(len(noMenus.([]interface{})), qt.Equals, 1) + c.Assert(len(noMenus.([]any)), qt.Equals, 1) } func TestLoadConfigDirError(t *testing.T) { diff --git a/hugolib/content_map.go b/hugolib/content_map.go index 29e821f75..330391dcb 100644 --- a/hugolib/content_map.go +++ b/hugolib/content_map.go @@ -83,7 +83,7 @@ func newContentMap(cfg contentMapConfig) *contentMap { m.sections, m.taxonomies, } - addToReverseMap := func(k string, n *contentNode, m map[interface{}]*contentNode) { + addToReverseMap := func(k string, n *contentNode, m map[any]*contentNode) { k = strings.ToLower(k) existing, found := m[k] if found && existing != ambiguousContentNode { @@ -96,8 +96,8 @@ func newContentMap(cfg contentMapConfig) *contentMap { m.pageReverseIndex = &contentTreeReverseIndex{ t: []*contentTree{m.pages, m.sections, m.taxonomies}, contentTreeReverseIndexMap: &contentTreeReverseIndexMap{ - initFn: func(t *contentTree, m map[interface{}]*contentNode) { - t.Walk(func(s string, v interface{}) bool { + initFn: func(t *contentTree, m map[any]*contentNode) { + t.Walk(func(s string, v any) bool { n := v.(*contentNode) if n.p != nil && !n.p.File().IsZero() { meta := n.p.File().FileInfo().Meta() @@ -396,7 +396,7 @@ func (m *contentMap) AddFilesBundle(header hugofs.FileMetaInfo, resources ...hug func (m *contentMap) CreateMissingNodes() error { // Create missing home and root sections - rootSections := make(map[string]interface{}) + rootSections := make(map[string]any) trackRootSection := func(s string, b *contentNode) { parts := strings.Split(s, "/") if len(parts) > 2 { @@ -409,7 +409,7 @@ func (m *contentMap) CreateMissingNodes() error { } } - m.sections.Walk(func(s string, v interface{}) bool { + m.sections.Walk(func(s string, v any) bool { n := v.(*contentNode) if s == "/" { @@ -420,7 +420,7 @@ func (m *contentMap) CreateMissingNodes() error { return false }) - m.pages.Walk(func(s string, v interface{}) bool { + m.pages.Walk(func(s string, v any) bool { trackRootSection(s, v.(*contentNode)) return false }) @@ -614,7 +614,7 @@ func (m *contentMap) deleteBundleMatching(matches func(b *contentNode) bool) { func (m *contentMap) deleteOrphanSections() { var sectionsToDelete []string - m.sections.Walk(func(s string, v interface{}) bool { + m.sections.Walk(func(s string, v any) bool { n := v.(*contentNode) if n.fi != nil { @@ -658,7 +658,7 @@ func (m *contentMap) deleteSectionByPath(s string) { } func (m *contentMap) deletePageByPath(s string) { - m.pages.Walk(func(s string, v interface{}) bool { + m.pages.Walk(func(s string, v any) bool { fmt.Println("S", s) return false @@ -689,14 +689,14 @@ func (m *contentMap) testDump() string { for i, r := range []*contentTree{m.pages, m.sections, m.resources} { sb.WriteString(fmt.Sprintf("Tree %d:\n", i)) - r.Walk(func(s string, v interface{}) bool { + r.Walk(func(s string, v any) bool { sb.WriteString("\t" + s + "\n") return false }) } for i, r := range []*contentTree{m.pages, m.sections} { - r.Walk(func(s string, v interface{}) bool { + r.Walk(func(s string, v any) bool { c := v.(*contentNode) cpToString := func(c *contentNode) string { var sb strings.Builder @@ -715,13 +715,13 @@ func (m *contentMap) testDump() string { if i == 1 { resourcesPrefix += cmLeafSeparator - m.pages.WalkPrefix(s+cmBranchSeparator, func(s string, v interface{}) bool { + m.pages.WalkPrefix(s+cmBranchSeparator, func(s string, v any) bool { sb.WriteString("\t - P: " + filepath.ToSlash((v.(*contentNode).fi.(hugofs.FileMetaInfo)).Meta().Filename) + "\n") return false }) } - m.resources.WalkPrefix(resourcesPrefix, func(s string, v interface{}) bool { + m.resources.WalkPrefix(resourcesPrefix, func(s string, v any) bool { sb.WriteString("\t - R: " + filepath.ToSlash((v.(*contentNode).fi.(hugofs.FileMetaInfo)).Meta().Filename) + "\n") return false }) @@ -791,7 +791,7 @@ type contentTrees []*contentTree func (t contentTrees) DeletePrefix(prefix string) int { var count int for _, tree := range t { - tree.Walk(func(s string, v interface{}) bool { + tree.Walk(func(s string, v any) bool { return false }) count += tree.DeletePrefix(prefix) @@ -836,7 +836,7 @@ func (c *contentTree) WalkQuery(query pageMapQuery, walkFn contentTreeNodeCallba filter = contentTreeNoListAlwaysFilter } if query.Prefix != "" { - c.WalkBelow(query.Prefix, func(s string, v interface{}) bool { + c.WalkBelow(query.Prefix, func(s string, v any) bool { n := v.(*contentNode) if filter != nil && filter(s, n) { return false @@ -847,7 +847,7 @@ func (c *contentTree) WalkQuery(query pageMapQuery, walkFn contentTreeNodeCallba return } - c.Walk(func(s string, v interface{}) bool { + c.Walk(func(s string, v any) bool { n := v.(*contentNode) if filter != nil && filter(s, n) { return false @@ -872,7 +872,7 @@ func (c contentTrees) WalkLinkable(fn contentTreeNodeCallback) { func (c contentTrees) Walk(fn contentTreeNodeCallback) { for _, tree := range c { - tree.Walk(func(s string, v interface{}) bool { + tree.Walk(func(s string, v any) bool { n := v.(*contentNode) return fn(s, n) }) @@ -881,7 +881,7 @@ func (c contentTrees) Walk(fn contentTreeNodeCallback) { func (c contentTrees) WalkPrefix(prefix string, fn contentTreeNodeCallback) { for _, tree := range c { - tree.WalkPrefix(prefix, func(s string, v interface{}) bool { + tree.WalkPrefix(prefix, func(s string, v any) bool { n := v.(*contentNode) return fn(s, n) }) @@ -891,7 +891,7 @@ func (c contentTrees) WalkPrefix(prefix string, fn contentTreeNodeCallback) { // WalkBelow walks the tree below the given prefix, i.e. it skips the // node with the given prefix as key. func (c *contentTree) WalkBelow(prefix string, fn radix.WalkFn) { - c.Tree.WalkPrefix(prefix, func(s string, v interface{}) bool { + c.Tree.WalkPrefix(prefix, func(s string, v any) bool { if s == prefix { return false } @@ -901,7 +901,7 @@ func (c *contentTree) WalkBelow(prefix string, fn radix.WalkFn) { func (c *contentTree) getMatch(matches func(b *contentNode) bool) string { var match string - c.Walk(func(s string, v interface{}) bool { + c.Walk(func(s string, v any) bool { n, ok := v.(*contentNode) if !ok { return false @@ -920,7 +920,7 @@ func (c *contentTree) getMatch(matches func(b *contentNode) bool) string { func (c *contentTree) hasBelow(s1 string) bool { var t bool - c.WalkBelow(s1, func(s2 string, v interface{}) bool { + c.WalkBelow(s1, func(s2 string, v any) bool { t = true return true }) @@ -928,14 +928,14 @@ func (c *contentTree) hasBelow(s1 string) bool { } func (c *contentTree) printKeys() { - c.Walk(func(s string, v interface{}) bool { + c.Walk(func(s string, v any) bool { fmt.Println(s) return false }) } func (c *contentTree) printKeysPrefix(prefix string) { - c.WalkPrefix(prefix, func(s string, v interface{}) bool { + c.WalkPrefix(prefix, func(s string, v any) bool { fmt.Println(s) return false }) @@ -1040,9 +1040,9 @@ type contentTreeReverseIndex struct { } type contentTreeReverseIndexMap struct { - m map[interface{}]*contentNode + m map[any]*contentNode init sync.Once - initFn func(*contentTree, map[interface{}]*contentNode) + initFn func(*contentTree, map[any]*contentNode) } func (c *contentTreeReverseIndex) Reset() { @@ -1051,9 +1051,9 @@ func (c *contentTreeReverseIndex) Reset() { } } -func (c *contentTreeReverseIndex) Get(key interface{}) *contentNode { +func (c *contentTreeReverseIndex) Get(key any) *contentNode { c.init.Do(func() { - c.m = make(map[interface{}]*contentNode) + c.m = make(map[any]*contentNode) for _, tree := range c.t { c.initFn(tree, c.m) } diff --git a/hugolib/content_map_page.go b/hugolib/content_map_page.go index e7661bb81..21a4e8f2a 100644 --- a/hugolib/content_map_page.go +++ b/hugolib/content_map_page.go @@ -66,7 +66,7 @@ func (m *pageMap) createMissingTaxonomyNodes() error { if m.cfg.taxonomyDisabled { return nil } - m.taxonomyEntries.Walk(func(s string, v interface{}) bool { + m.taxonomyEntries.Walk(func(s string, v any) bool { n := v.(*contentNode) vi := n.viewInfo k := cleanSectionTreeKey(vi.name.plural + "/" + vi.termKey) @@ -174,7 +174,7 @@ func (m *pageMap) newPageFromContentNode(n *contentNode, parentBucket *pagesMapB return nil, err } - ps.init.Add(func() (interface{}, error) { + ps.init.Add(func() (any, error) { pp, err := newPagePaths(s, ps, metaProvider) if err != nil { return nil, err @@ -271,7 +271,7 @@ func (m *pageMap) newResource(fim hugofs.FileMetaInfo, owner *pageState) (resour func (m *pageMap) createSiteTaxonomies() error { m.s.taxonomies = make(TaxonomyList) var walkErr error - m.taxonomies.Walk(func(s string, v interface{}) bool { + m.taxonomies.Walk(func(s string, v any) bool { n := v.(*contentNode) t := n.viewInfo @@ -285,7 +285,7 @@ func (m *pageMap) createSiteTaxonomies() error { walkErr = errors.Errorf("missing taxonomy: %s", viewName.plural) return true } - m.taxonomyEntries.WalkPrefix(s, func(ss string, v interface{}) bool { + m.taxonomyEntries.WalkPrefix(s, func(ss string, v any) bool { b2 := v.(*contentNode) info := b2.viewInfo taxonomy.add(info.termKey, page.NewWeightedPage(info.weight, info.ref.p, n.p)) @@ -337,7 +337,7 @@ func (m *pageMap) assemblePages() error { return err } - m.pages.Walk(func(s string, v interface{}) bool { + m.pages.Walk(func(s string, v any) bool { n := v.(*contentNode) var shouldBuild bool @@ -397,7 +397,7 @@ func (m *pageMap) assemblePages() error { func (m *pageMap) assembleResources(s string, p *pageState, parentBucket *pagesMapBucket) error { var err error - m.resources.WalkPrefix(s, func(s string, v interface{}) bool { + m.resources.WalkPrefix(s, func(s string, v any) bool { n := v.(*contentNode) meta := n.fi.Meta() classifier := meta.Classifier @@ -432,7 +432,7 @@ func (m *pageMap) assembleSections() error { var sectionsToDelete []string var err error - m.sections.Walk(func(s string, v interface{}) bool { + m.sections.Walk(func(s string, v any) bool { n := v.(*contentNode) var shouldBuild bool @@ -517,7 +517,7 @@ func (m *pageMap) assembleTaxonomies() error { var taxonomiesToDelete []string var err error - m.taxonomies.Walk(func(s string, v interface{}) bool { + m.taxonomies.Walk(func(s string, v any) bool { n := v.(*contentNode) if n.p != nil { @@ -861,7 +861,7 @@ func (b *pagesMapBucket) getTaxonomyEntries() page.Pages { ref := b.owner.treeRef viewInfo := ref.n.viewInfo prefix := strings.ToLower("/" + viewInfo.name.plural + "/" + viewInfo.termKey + "/") - ref.m.taxonomyEntries.WalkPrefix(prefix, func(s string, v interface{}) bo |