Skip to content

Commit

Permalink
reflect.PointerTo is supported only from go1.20, use a dummy variable…
Browse files Browse the repository at this point in the history
… to get the pointer type
  • Loading branch information
tiltwind committed Feb 12, 2023
1 parent 6ba7808 commit ec3010f
Showing 1 changed file with 42 additions and 24 deletions.
66 changes: 42 additions & 24 deletions const.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,30 +241,48 @@ var DescRegex, _ = regexp.Compile(DESC_REGEX)
var NilValue = reflect.Zero(reflect.TypeOf((*interface{})(nil)).Elem())

var (
_typeOfInt = reflect.TypeOf(0)
_typeOfInt8 = reflect.TypeOf(int8(0))
_typeOfInt16 = reflect.TypeOf(int16(0))
_typeOfInt32 = reflect.TypeOf(int32(0))
_typeOfInt64 = reflect.TypeOf(int64(0))
_typeOfUint = reflect.TypeOf(uint(0))
_typeOfUint8 = reflect.TypeOf(uint8(0))
_typeOfUint16 = reflect.TypeOf(uint16(0))
_typeOfUint32 = reflect.TypeOf(uint32(0))
_typeOfUint64 = reflect.TypeOf(uint64(0))
_typeOfFloat32 = reflect.TypeOf(float32(0))
_typeOfFloat64 = reflect.TypeOf(float64(0))
// reflect.PointerTo is supported only from go1.20.
// So we use a dummy variable to get the pointer type.
_varInt = 0
_varInt8 = int8(0)
_varInt16 = int16(0)
_varInt32 = int32(0)
_varInt64 = int64(0)
_varUint = uint(0)
_varUint8 = uint8(0)
_varUint16 = uint16(0)
_varUint32 = uint32(0)
_varUint64 = uint64(0)
_varFloat32 = float32(0)
_varFloat64 = float64(0)
)

var (
_typeOfInt = reflect.TypeOf(_varInt)
_typeOfInt8 = reflect.TypeOf(_varInt8)
_typeOfInt16 = reflect.TypeOf(_varInt16)
_typeOfInt32 = reflect.TypeOf(_varInt32)
_typeOfInt64 = reflect.TypeOf(_varInt64)
_typeOfUint = reflect.TypeOf(_varUint)
_typeOfUint8 = reflect.TypeOf(_varUint8)
_typeOfUint16 = reflect.TypeOf(_varUint16)
_typeOfUint32 = reflect.TypeOf(_varUint32)
_typeOfUint64 = reflect.TypeOf(_varUint64)
_typeOfFloat32 = reflect.TypeOf(_varFloat32)
_typeOfFloat64 = reflect.TypeOf(_varFloat64)
)

var (
_typeOfIntPtr = reflect.PointerTo(_typeOfInt)
_typeOfInt8Ptr = reflect.PointerTo(_typeOfInt8)
_typeOfInt16Ptr = reflect.PointerTo(_typeOfInt16)
_typeOfInt32Ptr = reflect.PointerTo(_typeOfInt32)
_typeOfInt64Ptr = reflect.PointerTo(_typeOfInt64)
_typeOfUintPtr = reflect.PointerTo(_typeOfUint)
_typeOfUint8Ptr = reflect.PointerTo(_typeOfUint8)
_typeOfUint16Ptr = reflect.PointerTo(_typeOfUint16)
_typeOfUint32Ptr = reflect.PointerTo(_typeOfUint32)
_typeOfUint64Ptr = reflect.PointerTo(_typeOfUint64)
_typeOfFloat32Ptr = reflect.PointerTo(_typeOfFloat32)
_typeOfFloat64Ptr = reflect.PointerTo(_typeOfFloat64)
_typeOfIntPtr = reflect.TypeOf(&_varInt)
_typeOfInt8Ptr = reflect.TypeOf(&_varInt8)
_typeOfInt16Ptr = reflect.TypeOf(&_varInt16)
_typeOfInt32Ptr = reflect.TypeOf(&_varInt32)
_typeOfInt64Ptr = reflect.TypeOf(&_varInt64)
_typeOfUintPtr = reflect.TypeOf(&_varUint)
_typeOfUint8Ptr = reflect.TypeOf(&_varUint8)
_typeOfUint16Ptr = reflect.TypeOf(&_varUint16)
_typeOfUint32Ptr = reflect.TypeOf(&_varUint32)
_typeOfUint64Ptr = reflect.TypeOf(&_varUint64)
_typeOfFloat32Ptr = reflect.TypeOf(&_varFloat32)
_typeOfFloat64Ptr = reflect.TypeOf(&_varFloat64)
)

0 comments on commit ec3010f

Please sign in to comment.