Skip to content

Commit

Permalink
use reflect.Pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
ungerik committed Oct 17, 2023
1 parent 16c5978 commit 3a10240
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 7 deletions.
1 change: 1 addition & 0 deletions go.work.sum
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw
golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIio=
golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw=
golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc=
golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4=
golang.org/x/mod v0.6.0/go.mod h1:4mET923SAdbXp2ki8ey+zGs1SLqsuM2Y0uvdZR/fUNI=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.10.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
Expand Down
4 changes: 2 additions & 2 deletions internal/pq/array.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ func (GenericArray) evaluateDestination(rt reflect.Type) (reflect.Type, func([]b
// TODO calculate the assign function for other types
// TODO repeat this section on the element type of arrays or slices (multidimensional)
{
if reflect.PtrTo(rt).Implements(typeSQLScanner) {
if reflect.PointerTo(rt).Implements(typeSQLScanner) {
// dest is always addressable because it is an element of a slice.
assign = func(src []byte, dest reflect.Value) (err error) {
ss := dest.Addr().Interface().(sql.Scanner)
Expand Down Expand Up @@ -387,7 +387,7 @@ FoundType:
func (a GenericArray) Scan(src any) error {
dpv := reflect.ValueOf(a.A)
switch {
case dpv.Kind() != reflect.Ptr:
case dpv.Kind() != reflect.Pointer:
return fmt.Errorf("pq: destination %T is not a pointer to array or slice", a.A)
case dpv.IsNil():
return fmt.Errorf("pq: destination %T is nil", a.A)
Expand Down
6 changes: 3 additions & 3 deletions json.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ func CanMarshalJSON(t reflect.Type) bool {
return true
}
kind := t.Kind()
if kind != reflect.Ptr && reflect.PtrTo(t).Implements(jsonMarshalerType) {
if kind != reflect.Pointer && reflect.PointerTo(t).Implements(jsonMarshalerType) {
return true
}

if t.Implements(textMarshalerType) {
return true
}
if kind != reflect.Ptr && reflect.PtrTo(t).Implements(textMarshalerType) {
if kind != reflect.Pointer && reflect.PointerTo(t).Implements(textMarshalerType) {
return true
}

if kind == reflect.Ptr {
if kind == reflect.Pointer {
t = t.Elem()
kind = t.Kind()
}
Expand Down
2 changes: 1 addition & 1 deletion nullable/nullable.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type Zeroable interface {
// with true returned for the zero value of reflect.Value.
func ReflectIsNull(v reflect.Value) bool {
switch v.Kind() {
case reflect.Ptr:
case reflect.Pointer:
if v.IsNil() {
return true
}
Expand Down
2 changes: 1 addition & 1 deletion strfmt/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func Scan(dest reflect.Value, source string, config *ScanConfig) (err error) {
return scaner.ScanString(dest, source, config)
}

if dest.Kind() == reflect.Ptr {
if dest.Kind() == reflect.Pointer {
if config.IsNil(source) {
// If dest is a pointer type and source is a nil string
// then set pointer to nil (the zero value of the pointer)
Expand Down

0 comments on commit 3a10240

Please sign in to comment.