From fd5757db6b7d6fbe067b57afc03fd13bfa8eedee Mon Sep 17 00:00:00 2001 From: "Arrobo, Gabriel" Date: Wed, 7 Oct 2026 13:11:41 -0700 Subject: [PATCH] Use reflect.Pointer and Ptr* helpers via new() Signed-off-by: Arrobo, Gabriel --- go.mod | 5 +---- go.sum | 4 ++-- utils.go | 22 +++++++++++----------- 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/go.mod b/go.mod index be4355c8..fa670e57 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,4 @@ require ( golang.org/x/oauth2 v0.37.0 ) -require ( - github.com/stretchr/testify v1.11.1 // indirect - go.uber.org/multierr v1.11.0 // indirect -) +require go.uber.org/multierr v1.11.0 // indirect diff --git a/go.sum b/go.sum index f6b60029..8de21443 100644 --- a/go.sum +++ b/go.sum @@ -2,8 +2,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= -github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= +github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= +github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= diff --git a/utils.go b/utils.go index 3be5d0c7..307c7384 100644 --- a/utils.go +++ b/utils.go @@ -30,28 +30,28 @@ import ( ) // PtrBool is a helper routine that returns a pointer to given boolean value. -func PtrBool(v bool) *bool { return &v } +func PtrBool(v bool) *bool { return new(v) } // PtrInt is a helper routine that returns a pointer to given integer value. -func PtrInt(v int) *int { return &v } +func PtrInt(v int) *int { return new(v) } // PtrInt32 is a helper routine that returns a pointer to given integer value. -func PtrInt32(v int32) *int32 { return &v } +func PtrInt32(v int32) *int32 { return new(v) } // PtrInt64 is a helper routine that returns a pointer to given integer value. -func PtrInt64(v int64) *int64 { return &v } +func PtrInt64(v int64) *int64 { return new(v) } // PtrFloat32 is a helper routine that returns a pointer to given float value. -func PtrFloat32(v float32) *float32 { return &v } +func PtrFloat32(v float32) *float32 { return new(v) } // PtrFloat64 is a helper routine that returns a pointer to given float value. -func PtrFloat64(v float64) *float64 { return &v } +func PtrFloat64(v float64) *float64 { return new(v) } // PtrString is a helper routine that returns a pointer to given string value. -func PtrString(v string) *string { return &v } +func PtrString(v string) *string { return new(v) } // PtrTime is helper routine that returns a pointer to given Time value. -func PtrTime(v time.Time) *time.Time { return &v } +func PtrTime(v time.Time) *time.Time { return new(v) } type NullableAny struct { value *any @@ -383,7 +383,7 @@ func IsNil(i any) bool { return true } switch reflect.TypeOf(i).Kind() { - case reflect.Chan, reflect.Func, reflect.Map, reflect.Ptr, reflect.UnsafePointer, reflect.Interface, reflect.Slice: + case reflect.Chan, reflect.Func, reflect.Map, reflect.Pointer, reflect.UnsafePointer, reflect.Interface, reflect.Slice: return reflect.ValueOf(i).IsNil() case reflect.Array: return reflect.ValueOf(i).IsZero() @@ -412,7 +412,7 @@ func Validate(v any) error { func validateValue(rv reflect.Value) error { switch rv.Kind() { - case reflect.Ptr, reflect.Interface: + case reflect.Pointer, reflect.Interface: if rv.IsNil() { return nil } @@ -450,7 +450,7 @@ func validateValue(rv reflect.Value) error { } func validateRegexp(rv reflect.Value, pattern string) error { - for rv.Kind() == reflect.Ptr || rv.Kind() == reflect.Interface { + for rv.Kind() == reflect.Pointer || rv.Kind() == reflect.Interface { if rv.IsNil() { return nil }