diff options
author | Bjørn Erik Pedersen <[email protected]> | 2022-03-17 22:03:27 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2022-03-17 22:03:27 +0100 |
commit | b80853de90b10171155b8f3fde47d64ec7bfa0dd (patch) | |
tree | 435d3dbf7a495a0c6ce64c9769e037179aa0d27b /tpl/data | |
parent | 423594e03a906ef4150f433666ff588b022c3c92 (diff) | |
download | hugo-b80853de90b10171155b8f3fde47d64ec7bfa0dd.tar.gz hugo-b80853de90b10171155b8f3fde47d64ec7bfa0dd.zip |
all: gofmt -w -r 'interface{} -> any' .
Updates #9687
Diffstat (limited to 'tpl/data')
-rw-r--r-- | tpl/data/data.go | 10 | ||||
-rw-r--r-- | tpl/data/data_test.go | 28 | ||||
-rw-r--r-- | tpl/data/init.go | 2 | ||||
-rw-r--r-- | tpl/data/resources.go | 2 |
4 files changed, 21 insertions, 21 deletions
diff --git a/tpl/data/data.go b/tpl/data/data.go index cfd847474..5e03d52c3 100644 --- a/tpl/data/data.go +++ b/tpl/data/data.go @@ -63,7 +63,7 @@ type Namespace struct { // The data separator can be a comma, semi-colon, pipe, etc, but only one character. // If you provide multiple parts for the URL they will be joined together to the final URL. // GetCSV returns nil or a slice slice to use in a short code. -func (ns *Namespace) GetCSV(sep string, args ...interface{}) (d [][]string, err error) { +func (ns *Namespace) GetCSV(sep string, args ...any) (d [][]string, err error) { url, headers := toURLAndHeaders(args) cache := ns.cacheGetCSV @@ -102,8 +102,8 @@ func (ns *Namespace) GetCSV(sep string, args ...interface{}) (d [][]string, err // GetJSON expects one or n-parts of a URL to a resource which can either be a local or a remote one. // If you provide multiple parts they will be joined together to the final URL. // GetJSON returns nil or parsed JSON to use in a short code. -func (ns *Namespace) GetJSON(args ...interface{}) (interface{}, error) { - var v interface{} +func (ns *Namespace) GetJSON(args ...any) (any, error) { + var v any url, headers := toURLAndHeaders(args) cache := ns.cacheGetJSON @@ -146,7 +146,7 @@ func addDefaultHeaders(req *http.Request, accepts ...string) { } } -func addUserProvidedHeaders(headers map[string]interface{}, req *http.Request) { +func addUserProvidedHeaders(headers map[string]any, req *http.Request) { if headers == nil { return } @@ -179,7 +179,7 @@ func hasHeaderKey(m http.Header, key string) bool { return ok } -func toURLAndHeaders(urlParts []interface{}) (string, map[string]interface{}) { +func toURLAndHeaders(urlParts []any) (string, map[string]any) { if len(urlParts) == 0 { return "", nil } diff --git a/tpl/data/data_test.go b/tpl/data/data_test.go index 8a18a19e4..3d365e5fb 100644 --- a/tpl/data/data_test.go +++ b/tpl/data/data_test.go @@ -35,7 +35,7 @@ func TestGetCSV(t *testing.T) { sep string url string content string - expect interface{} + expect any }{ // Remotes { @@ -129,12 +129,12 @@ func TestGetJSON(t *testing.T) { for i, test := range []struct { url string content string - expect interface{} + expect any }{ { `http://success/`, `{"gomeetup":["Sydney","San Francisco","Stockholm"]}`, - map[string]interface{}{"gomeetup": []interface{}{"Sydney", "San Francisco", "Stockholm"}}, + map[string]any{"gomeetup": []any{"Sydney", "San Francisco", "Stockholm"}}, }, { `http://malformed/`, @@ -150,7 +150,7 @@ func TestGetJSON(t *testing.T) { { "pass/semi", `{"gomeetup":["Sydney","San Francisco","Stockholm"]}`, - map[string]interface{}{"gomeetup": []interface{}{"Sydney", "San Francisco", "Stockholm"}}, + map[string]any{"gomeetup": []any{"Sydney", "San Francisco", "Stockholm"}}, }, { "fail/no-file", @@ -160,7 +160,7 @@ func TestGetJSON(t *testing.T) { { `pass/üńīçøðê-url.json`, `{"gomeetup":["Sydney","San Francisco","Stockholm"]}`, - map[string]interface{}{"gomeetup": []interface{}{"Sydney", "San Francisco", "Stockholm"}}, + map[string]any{"gomeetup": []any{"Sydney", "San Francisco", "Stockholm"}}, }, } { @@ -218,12 +218,12 @@ func TestHeaders(t *testing.T) { for _, test := range []struct { name string - headers interface{} + headers any assert func(c *qt.C, headers string) }{ { `Misc header variants`, - map[string]interface{}{ + map[string]any{ "Accept-Charset": "utf-8", "Max-forwards": "10", "X-Int": 32, @@ -254,7 +254,7 @@ func TestHeaders(t *testing.T) { }, { `Override User-Agent`, - map[string]interface{}{ + map[string]any{ "User-Agent": "007", }, func(c *qt.C, headers string) { @@ -278,7 +278,7 @@ func TestHeaders(t *testing.T) { }) defer func() { srv.Close() }() - testFunc := func(fn func(args ...interface{}) error) { + testFunc := func(fn func(args ...any) error) { defer headers.Reset() err := fn("http://example.org/api", "?foo", test.headers) @@ -287,11 +287,11 @@ func TestHeaders(t *testing.T) { test.assert(c, headers.String()) } - testFunc(func(args ...interface{}) error { + testFunc(func(args ...any) error { _, err := ns.GetJSON(args...) return err }) - testFunc(func(args ...interface{}) error { + testFunc(func(args ...any) error { _, err := ns.GetCSV(",", args...) return err }) @@ -304,13 +304,13 @@ func TestHeaders(t *testing.T) { func TestToURLAndHeaders(t *testing.T) { t.Parallel() c := qt.New(t) - url, headers := toURLAndHeaders([]interface{}{"https://foo?id=", 32}) + url, headers := toURLAndHeaders([]any{"https://foo?id=", 32}) c.Assert(url, qt.Equals, "https://foo?id=32") c.Assert(headers, qt.IsNil) - url, headers = toURLAndHeaders([]interface{}{"https://foo?id=", 32, map[string]interface{}{"a": "b"}}) + url, headers = toURLAndHeaders([]any{"https://foo?id=", 32, map[string]any{"a": "b"}}) c.Assert(url, qt.Equals, "https://foo?id=32") - c.Assert(headers, qt.DeepEquals, map[string]interface{}{"a": "b"}) + c.Assert(headers, qt.DeepEquals, map[string]any{"a": "b"}) } func TestParseCSV(t *testing.T) { diff --git a/tpl/data/init.go b/tpl/data/init.go index 5ac24eaab..22e685fc8 100644 --- a/tpl/data/init.go +++ b/tpl/data/init.go @@ -26,7 +26,7 @@ func init() { ns := &internal.TemplateFuncsNamespace{ Name: name, - Context: func(args ...interface{}) (interface{}, error) { return ctx, nil }, + Context: func(args ...any) (any, error) { return ctx, nil }, } ns.AddMethodMapping(ctx.GetCSV, diff --git a/tpl/data/resources.go b/tpl/data/resources.go index b4b310bcc..dca25efb2 100644 --- a/tpl/data/resources.go +++ b/tpl/data/resources.go @@ -44,7 +44,7 @@ func (ns *Namespace) getRemote(cache *filecache.Cache, unmarshal func([]byte) (b if err := ns.deps.ExecHelper.Sec().CheckAllowedHTTPMethod("GET"); err != nil { return err } - + var headers bytes.Buffer req.Header.Write(&headers) id := helpers.MD5String(url + headers.String()) |