Skip to content

Commit

Permalink
chore: run gofmt -w -r 'interface{} -> any'
Browse files Browse the repository at this point in the history
  • Loading branch information
jszwec committed Feb 14, 2023
1 parent 46f1e77 commit 21889c0
Show file tree
Hide file tree
Showing 13 changed files with 350 additions and 343 deletions.
1 change: 1 addition & 0 deletions cache_go17.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !go1.9
// +build !go1.9

package csvutil
Expand Down
1 change: 1 addition & 0 deletions cache_go19.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build go1.9
// +build go1.9

package csvutil
Expand Down
8 changes: 4 additions & 4 deletions csvutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ var (
//
// In case of success the provided slice will be reinitialized and its content
// fully replaced with decoded data.
func Unmarshal(data []byte, v interface{}) error {
func Unmarshal(data []byte, v any) error {
val := reflect.ValueOf(v)

if val.Kind() != reflect.Ptr || val.IsNil() {
Expand Down Expand Up @@ -90,7 +90,7 @@ func Unmarshal(data []byte, v interface{}) error {
// Marshal will always encode the CSV header even for the empty slice.
//
// For the exact encoding rules look at Encoder.Encode method.
func Marshal(v interface{}) ([]byte, error) {
func Marshal(v any) ([]byte, error) {
val := walkValue(reflect.ValueOf(v))

if !val.IsValid() {
Expand Down Expand Up @@ -177,7 +177,7 @@ func countRecords(s []byte) (n int) {
//
// Header will return UnsupportedTypeError if the provided value is nil or is
// not a struct.
func Header(v interface{}, tag string) ([]string, error) {
func Header(v any, tag string) ([]string, error) {
typ, err := valueType(v)
if err != nil {
return nil, err
Expand All @@ -195,7 +195,7 @@ func Header(v interface{}, tag string) ([]string, error) {
return h, nil
}

func valueType(v interface{}) (reflect.Type, error) {
func valueType(v any) (reflect.Type, error) {
val := reflect.ValueOf(v)
if !val.IsValid() {
return nil, &UnsupportedTypeError{}
Expand Down
1 change: 1 addition & 0 deletions csvutil_go113_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build go1.13
// +build go1.13

package csvutil
Expand Down
1 change: 1 addition & 0 deletions csvutil_go17.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !go1.9
// +build !go1.9

package csvutil
Expand Down
1 change: 1 addition & 0 deletions csvutil_go19.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build go1.9
// +build go1.9

package csvutil
Expand Down
1 change: 1 addition & 0 deletions csvutil_race_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build race
// +build race

package csvutil
Expand Down
22 changes: 11 additions & 11 deletions csvutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ func TestUnmarshal(t *testing.T) {
fixture := []struct {
desc string
src []byte
in interface{}
out interface{}
in any
out any
}{
{
desc: "type with two records",
Expand Down Expand Up @@ -177,10 +177,10 @@ func TestUnmarshal(t *testing.T) {

var fixtures = []struct {
desc string
v interface{}
v any
expected string
}{
{"nil interface", interface{}(nil), "csvutil: Unmarshal(nil)"},
{"nil interface", any(nil), "csvutil: Unmarshal(nil)"},
{"nil", nil, "csvutil: Unmarshal(nil)"},
{"non pointer struct", struct{}{}, "csvutil: Unmarshal(non-pointer struct {})"},
{"invalid type double pointer int", (**int)(nil), "csvutil: Unmarshal(invalid type **int)"},
Expand Down Expand Up @@ -279,7 +279,7 @@ line2,"line2"`),
func TestMarshal(t *testing.T) {
fixtures := []struct {
desc string
v interface{}
v any
out [][]string
err error
}{
Expand Down Expand Up @@ -353,7 +353,7 @@ func TestMarshal(t *testing.T) {
},
{
desc: "slice pointer wrapped in interface",
v: func() (v interface{}) {
v: func() (v any) {
v = &[]*TypeI{
{String: "string", Int: 10},
}
Expand All @@ -366,7 +366,7 @@ func TestMarshal(t *testing.T) {
},
{
desc: "array pointer wrapped in interface",
v: func() (v interface{}) {
v: func() (v any) {
v = &[1]*TypeI{
{String: "string", Int: 10},
}
Expand Down Expand Up @@ -450,7 +450,7 @@ func TestMarshal(t *testing.T) {
fixtures := []struct {
desc string
expected string
v interface{}
v any
}{
{
desc: "int64",
Expand Down Expand Up @@ -554,7 +554,7 @@ type Embedded16 struct {
func TestHeader(t *testing.T) {
fixture := []struct {
desc string
v interface{}
v any
tag string
header []string
err error
Expand Down Expand Up @@ -889,7 +889,7 @@ func checkErr(expected, err error) bool {
//
// This copy exists because we want to avoid dependencies like:
// "golang.org/x/xerrors"
func asError(err error, target interface{}) bool {
func asError(err error, target any) bool {
if target == nil {
panic("errors: target cannot be nil")
}
Expand All @@ -907,7 +907,7 @@ func asError(err error, target interface{}) bool {
val.Elem().Set(reflect.ValueOf(err))
return true
}
if x, ok := err.(interface{ As(interface{}) bool }); ok && x.As(target) {
if x, ok := err.(interface{ As(any) bool }); ok && x.As(target) {
return true
}
err = unwrap(err)
Expand Down
8 changes: 4 additions & 4 deletions decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type decField struct {
columnIndex int
field
decodeFunc
zero interface{}
zero any
}

// A Decoder reads and decodes string records into structs.
Expand Down Expand Up @@ -45,7 +45,7 @@ type Decoder struct {
// value of that type.
//
// Map must be set before the first call to Decode and not changed after it.
Map func(field, col string, v interface{}) string
Map func(field, col string, v any) string

r Reader
typeKey typeKey
Expand Down Expand Up @@ -170,7 +170,7 @@ func NewDecoder(r Reader, header ...string) (dec *Decoder, err error) {
//
// Fields with inline tags that have a non-empty prefix must not be cyclic
// structures. Passing such values to Decode will result in an infinite loop.
func (d *Decoder) Decode(v interface{}) (err error) {
func (d *Decoder) Decode(v any) (err error) {
val := reflect.ValueOf(v)
if val.Kind() != reflect.Ptr || val.IsNil() {
return &InvalidDecodeError{Type: reflect.TypeOf(v)}
Expand Down Expand Up @@ -264,7 +264,7 @@ func (d *Decoder) Unused() []int {
//
// Deprecated: use UnmarshalFunc function with type parameter instead. The benefits
// are type safety and much better performance.
func (d *Decoder) Register(f interface{}) {
func (d *Decoder) Register(f any) {
v := reflect.ValueOf(f)
typ := v.Type()

Expand Down

0 comments on commit 21889c0

Please sign in to comment.