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 /common/collections | |
parent | 423594e03a906ef4150f433666ff588b022c3c92 (diff) |
all: gofmt -w -r 'interface{} -> any' .
Updates #9687
Diffstat (limited to 'common/collections')
-rw-r--r-- | common/collections/append.go | 10 | ||||
-rw-r--r-- | common/collections/append_test.go | 38 | ||||
-rw-r--r-- | common/collections/collections.go | 2 | ||||
-rw-r--r-- | common/collections/slice.go | 8 | ||||
-rw-r--r-- | common/collections/slice_test.go | 32 |
5 files changed, 45 insertions, 45 deletions
diff --git a/common/collections/append.go b/common/collections/append.go index d6fb89241..a9c14c1aa 100644 --- a/common/collections/append.go +++ b/common/collections/append.go @@ -21,7 +21,7 @@ import ( // Append appends from to a slice to and returns the resulting slice. // If length of from is one and the only element is a slice of same type as to, // it will be appended. -func Append(to interface{}, from ...interface{}) (interface{}, error) { +func Append(to any, from ...any) (any, error) { tov, toIsNil := indirect(reflect.ValueOf(to)) toIsNil = toIsNil || to == nil @@ -73,8 +73,8 @@ func Append(to interface{}, from ...interface{}) (interface{}, error) { return tov.Interface(), nil } -func appendToInterfaceSliceFromValues(slice1, slice2 reflect.Value) ([]interface{}, error) { - var tos []interface{} +func appendToInterfaceSliceFromValues(slice1, slice2 reflect.Value) ([]any, error) { + var tos []any for _, slice := range []reflect.Value{slice1, slice2} { for i := 0; i < slice.Len(); i++ { @@ -85,8 +85,8 @@ func appendToInterfaceSliceFromValues(slice1, slice2 reflect.Value) ([]interface return tos, nil } -func appendToInterfaceSlice(tov reflect.Value, from ...interface{}) ([]interface{}, error) { - var tos []interface{} +func appendToInterfaceSlice(tov reflect.Value, from ...any) ([]any, error) { + var tos []any for i := 0; i < tov.Len(); i++ { tos = append(tos, tov.Index(i).Interface()) diff --git a/common/collections/append_test.go b/common/collections/append_test.go index 7d6117de8..6df32fee6 100644 --- a/common/collections/append_test.go +++ b/common/collections/append_test.go @@ -25,25 +25,25 @@ func TestAppend(t *testing.T) { c := qt.New(t) for _, test := range []struct { - start interface{} - addend []interface{} - expected interface{} + start any + addend []any + expected any }{ - {[]string{"a", "b"}, []interface{}{"c"}, []string{"a", "b", "c"}}, - {[]string{"a", "b"}, []interface{}{"c", "d", "e"}, []string{"a", "b", "c", "d", "e"}}, - {[]string{"a", "b"}, []interface{}{[]string{"c", "d", "e"}}, []string{"a", "b", "c", "d", "e"}}, - {[]string{"a"}, []interface{}{"b", template.HTML("c")}, []interface{}{"a", "b", template.HTML("c")}}, - {nil, []interface{}{"a", "b"}, []string{"a", "b"}}, - {nil, []interface{}{nil}, []interface{}{nil}}, - {[]interface{}{}, []interface{}{[]string{"c", "d", "e"}}, []string{"c", "d", "e"}}, + {[]string{"a", "b"}, []any{"c"}, []string{"a", "b", "c"}}, + {[]string{"a", "b"}, []any{"c", "d", "e"}, []string{"a", "b", "c", "d", "e"}}, + {[]string{"a", "b"}, []any{[]string{"c", "d", "e"}}, []string{"a", "b", "c", "d", "e"}}, + {[]string{"a"}, []any{"b", template.HTML("c")}, []any{"a", "b", template.HTML("c")}}, + {nil, []any{"a", "b"}, []string{"a", "b"}}, + {nil, []any{nil}, []any{nil}}, + {[]any{}, []any{[]string{"c", "d", "e"}}, []string{"c", "d", "e"}}, { tstSlicers{&tstSlicer{"a"}, &tstSlicer{"b"}}, - []interface{}{&tstSlicer{"c"}}, + []any{&tstSlicer{"c"}}, tstSlicers{&tstSlicer{"a"}, &tstSlicer{"b"}, &tstSlicer{"c"}}, }, { &tstSlicers{&tstSlicer{"a"}, &tstSlicer{"b"}}, - []interface{}{&tstSlicer{"c"}}, + []any{&tstSlicer{"c"}}, tstSlicers{ &tstSlicer{"a"}, &tstSlicer{"b"}, @@ -52,26 +52,26 @@ func TestAppend(t *testing.T) { }, { testSlicerInterfaces{&tstSlicerIn1{"a"}, &tstSlicerIn1{"b"}}, - []interface{}{&tstSlicerIn1{"c"}}, + []any{&tstSlicerIn1{"c"}}, testSlicerInterfaces{&tstSlicerIn1{"a"}, &tstSlicerIn1{"b"}, &tstSlicerIn1{"c"}}, }, //https://github.com/gohugoio/hugo/issues/5361 { []string{"a", "b"}, - []interface{}{tstSlicers{&tstSlicer{"a"}, &tstSlicer{"b"}}}, - []interface{}{"a", "b", &tstSlicer{"a"}, &tstSlicer{"b"}}, + []any{tstSlicers{&tstSlicer{"a"}, &tstSlicer{"b"}}}, + []any{"a", "b", &tstSlicer{"a"}, &tstSlicer{"b"}}, }, { []string{"a", "b"}, - []interface{}{&tstSlicer{"a"}}, - []interface{}{"a", "b", &tstSlicer{"a"}}, + []any{&tstSlicer{"a"}}, + []any{"a", "b", &tstSlicer{"a"}}, }, // Errors - {"", []interface{}{[]string{"a", "b"}}, false}, + {"", []any{[]string{"a", "b"}}, false}, // No string concatenation. { "ab", - []interface{}{"c"}, + []any{"c"}, false, }, } { diff --git a/common/collections/collections.go b/common/collections/collections.go index bb47c8acc..0b46abee9 100644 --- a/common/collections/collections.go +++ b/common/collections/collections.go @@ -17,5 +17,5 @@ package collections // Grouper defines a very generic way to group items by a given key. type Grouper interface { - Group(key interface{}, items interface{}) (interface{}, error) + Group(key any, items any) (any, error) } diff --git a/common/collections/slice.go b/common/collections/slice.go index 07ad48eb3..51cb6ec1f 100644 --- a/common/collections/slice.go +++ b/common/collections/slice.go @@ -21,11 +21,11 @@ import ( // in collections.Slice template func to get types such as Pages, PageGroups etc. // instead of the less useful []interface{}. type Slicer interface { - Slice(items interface{}) (interface{}, error) + Slice(items any) (any, error) } // Slice returns a slice of all passed arguments. -func Slice(args ...interface{}) interface{} { +func Slice(args ...any) any { if len(args) == 0 { return args } @@ -66,8 +66,8 @@ func Slice(args ...interface{}) interface{} { } // StringSliceToInterfaceSlice converts ss to []interface{}. -func StringSliceToInterfaceSlice(ss []string) []interface{} { - result := make([]interface{}, len(ss)) +func StringSliceToInterfaceSlice(ss []string) []any { + result := make([]any, len(ss)) for i, s := range ss { result[i] = s } diff --git a/common/collections/slice_test.go b/common/collections/slice_test.go index 93bad84da..8e6553994 100644 --- a/common/collections/slice_test.go +++ b/common/collections/slice_test.go @@ -46,8 +46,8 @@ type tstSlicer struct { TheName string } -func (p *tstSlicerIn1) Slice(in interface{}) (interface{}, error) { - items := in.([]interface{}) +func (p *tstSlicerIn1) Slice(in any) (any, error) { + items := in.([]any) result := make(testSlicerInterfaces, len(items)) for i, v := range items { switch vv := v.(type) { @@ -60,8 +60,8 @@ func (p *tstSlicerIn1) Slice(in interface{}) (interface{}, error) { return result, nil } -func (p *tstSlicerIn2) Slice(in interface{}) (interface{}, error) { - items := in.([]interface{}) +func (p *tstSlicerIn2) Slice(in any) (any, error) { + items := in.([]any) result := make(testSlicerInterfaces, len(items)) for i, v := range items { switch vv := v.(type) { @@ -82,8 +82,8 @@ func (p *tstSlicerIn2) Name() string { return p.TheName } -func (p *tstSlicer) Slice(in interface{}) (interface{}, error) { - items := in.([]interface{}) +func (p *tstSlicer) Slice(in any) (any, error) { + items := in.([]any) result := make(tstSlicers, len(items)) for i, v := range items { switch vv := v.(type) { @@ -103,17 +103,17 @@ func TestSlice(t *testing.T) { c := qt.New(t) for i, test := range []struct { - args []interface{} - expected interface{} + args []any + expected any }{ - {[]interface{}{"a", "b"}, []string{"a", "b"}}, - {[]interface{}{&tstSlicer{"a"}, &tstSlicer{"b"}}, tstSlicers{&tstSlicer{"a"}, &tstSlicer{"b"}}}, - {[]interface{}{&tstSlicer{"a"}, "b"}, []interface{}{&tstSlicer{"a"}, "b"}}, - {[]interface{}{}, []interface{}{}}, - {[]interface{}{nil}, []interface{}{nil}}, - {[]interface{}{5, "b"}, []interface{}{5, "b"}}, - {[]interface{}{&tstSlicerIn1{"a"}, &tstSlicerIn2{"b"}}, testSlicerInterfaces{&tstSlicerIn1{"a"}, &tstSlicerIn2{"b"}}}, - {[]interface{}{&tstSlicerIn1{"a"}, &tstSlicer{"b"}}, []interface{}{&tstSlicerIn1{"a"}, &tstSlicer{"b"}}}, + {[]any{"a", "b"}, []string{"a", "b"}}, + {[]any{&tstSlicer{"a"}, &tstSlicer{"b"}}, tstSlicers{&tstSlicer{"a"}, &tstSlicer{"b"}}}, + {[]any{&tstSlicer{"a"}, "b"}, []any{&tstSlicer{"a"}, "b"}}, + {[]any{}, []any{}}, + {[]any{nil}, []any{nil}}, + {[]any{5, "b"}, []any{5, "b"}}, + {[]any{&tstSlicerIn1{"a"}, &tstSlicerIn2{"b"}}, testSlicerInterfaces{&tstSlicerIn1{"a"}, &tstSlicerIn2{"b"}}}, + {[]any{&tstSlicerIn1{"a"}, &tstSlicer{"b"}}, []any{&tstSlicerIn1{"a"}, &tstSlicer{"b"}}}, } { errMsg := qt.Commentf("[%d] %v", i, test.args) |