Source File
convert.go
Belonging Package
github.com/jackc/pgtype
func ( interface{}) (interface{}, bool) {
:= reflect.ValueOf()
switch .Kind() {
case reflect.Ptr:
if .IsNil() {
return nil, false
}
:= .Elem().Interface()
return , true
case reflect.Int:
:= int(.Int())
return , reflect.TypeOf() != .Type()
case reflect.Int8:
:= int8(.Int())
return , reflect.TypeOf() != .Type()
case reflect.Int16:
:= int16(.Int())
return , reflect.TypeOf() != .Type()
case reflect.Int32:
:= int32(.Int())
return , reflect.TypeOf() != .Type()
case reflect.Int64:
:= int64(.Int())
return , reflect.TypeOf() != .Type()
case reflect.Uint:
:= uint(.Uint())
return , reflect.TypeOf() != .Type()
case reflect.Uint8:
:= uint8(.Uint())
return , reflect.TypeOf() != .Type()
case reflect.Uint16:
:= uint16(.Uint())
return , reflect.TypeOf() != .Type()
case reflect.Uint32:
:= uint32(.Uint())
return , reflect.TypeOf() != .Type()
case reflect.Uint64:
:= uint64(.Uint())
return , reflect.TypeOf() != .Type()
case reflect.Float32:
:= float32(.Float())
return , reflect.TypeOf() != .Type()
case reflect.Float64:
:= .Float()
return , reflect.TypeOf() != .Type()
case reflect.String:
:= .String()
return , reflect.TypeOf() != .Type()
}
return nil, false
}
func ( interface{}) (interface{}, bool) {
:= reflect.ValueOf()
switch .Kind() {
case reflect.Ptr:
if .IsNil() {
return nil, false
}
:= .Elem().Interface()
return , true
case reflect.Slice:
if .Type().Elem().Kind() == reflect.Uint8 {
:= .Bytes()
return , reflect.TypeOf() != .Type()
}
}
return nil, false
}
func ( interface{}) (interface{}, bool) {
:= reflect.ValueOf()
switch .Kind() {
case reflect.Ptr:
if .IsNil() {
return nil, false
}
:= .Elem().Interface()
return , true
case reflect.Slice:
:= reflect.SliceOf(.Type().Elem())
if .Type().ConvertibleTo() {
:= .Convert()
return .Interface(), reflect.TypeOf(.Interface()) != .Type()
}
}
return nil, false
}
func ( int64, Status, interface{}) error {
if == Present {
switch v := .(type) {
case *int:
if < int64(minInt) {
return fmt.Errorf("%d is less than minimum value for int", )
} else if > int64(maxInt) {
return fmt.Errorf("%d is greater than maximum value for int", )
}
* = int()
case *int8:
if < math.MinInt8 {
return fmt.Errorf("%d is less than minimum value for int8", )
} else if > math.MaxInt8 {
return fmt.Errorf("%d is greater than maximum value for int8", )
}
* = int8()
case *int16:
if < math.MinInt16 {
return fmt.Errorf("%d is less than minimum value for int16", )
} else if > math.MaxInt16 {
return fmt.Errorf("%d is greater than maximum value for int16", )
}
* = int16()
case *int32:
if < math.MinInt32 {
return fmt.Errorf("%d is less than minimum value for int32", )
} else if > math.MaxInt32 {
return fmt.Errorf("%d is greater than maximum value for int32", )
}
* = int32()
case *int64:
if < math.MinInt64 {
return fmt.Errorf("%d is less than minimum value for int64", )
} else if > math.MaxInt64 {
return fmt.Errorf("%d is greater than maximum value for int64", )
}
* = int64()
case *uint:
if < 0 {
return fmt.Errorf("%d is less than zero for uint", )
} else if uint64() > uint64(maxUint) {
return fmt.Errorf("%d is greater than maximum value for uint", )
}
* = uint()
case *uint8:
if < 0 {
return fmt.Errorf("%d is less than zero for uint8", )
} else if > math.MaxUint8 {
return fmt.Errorf("%d is greater than maximum value for uint8", )
}
* = uint8()
case *uint16:
if < 0 {
return fmt.Errorf("%d is less than zero for uint32", )
} else if > math.MaxUint16 {
return fmt.Errorf("%d is greater than maximum value for uint16", )
}
* = uint16()
case *uint32:
if < 0 {
return fmt.Errorf("%d is less than zero for uint32", )
} else if > math.MaxUint32 {
return fmt.Errorf("%d is greater than maximum value for uint32", )
}
* = uint32()
case *uint64:
if < 0 {
return fmt.Errorf("%d is less than zero for uint64", )
}
* = uint64()
case sql.Scanner:
return .Scan()
default:
if := reflect.ValueOf(); .Kind() == reflect.Ptr {
:= .Elem()
.Set(reflect.New(.Type().Elem()))
}
return (, , .Interface())
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
if .OverflowInt(int64()) {
return fmt.Errorf("cannot put %d into %T", , )
}
.SetInt(int64())
return nil
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
if < 0 {
return fmt.Errorf("%d is less than zero for %T", , )
}
if .OverflowUint(uint64()) {
return fmt.Errorf("cannot put %d into %T", , )
}
.SetUint(uint64())
return nil
}
}
return fmt.Errorf("cannot assign %v into %T", , )
}
return nil
}
if := reflect.ValueOf(); .Kind() == reflect.Ptr {
:= .Elem()
if .Kind() == reflect.Ptr {
.Set(reflect.Zero(.Type()))
return nil
}
}
return fmt.Errorf("cannot assign %v %v into %T", , , )
}
func ( float64, Status, interface{}) error {
if == Present {
switch v := .(type) {
case *float32:
* = float32()
case *float64:
* =
default:
if := reflect.ValueOf(); .Kind() == reflect.Ptr {
:= .Elem()
.Set(reflect.New(.Type().Elem()))
}
return (, , .Interface())
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
:= int64()
if float64() == {
return int64AssignTo(, , )
}
}
}
return fmt.Errorf("cannot assign %v into %T", , )
}
return nil
}
if , := kindTypes[.Kind()]; {
:= .Convert(reflect.PtrTo())
return .Interface(), .Type() != .Type()
}
if .Kind() == reflect.Slice {
if , := kindTypes[.Type().Elem().Kind()]; {
:= reflect.PtrTo(reflect.SliceOf())
:= .Convert()
return .Interface(), .Type() != .Type()
}
}
if .Kind() == reflect.Array {
if , := kindTypes[.Type().Elem().Kind()]; {
:= reflect.PtrTo(reflect.ArrayOf(.Len(), ))
:= .Convert()
return .Interface(), .Type() != .Type()
}
}
return nil, false
}
func () {
kindTypes = map[reflect.Kind]reflect.Type{
reflect.Bool: reflect.TypeOf(false),
reflect.Float32: reflect.TypeOf(float32(0)),
reflect.Float64: reflect.TypeOf(float64(0)),
reflect.Int: reflect.TypeOf(int(0)),
reflect.Int8: reflect.TypeOf(int8(0)),
reflect.Int16: reflect.TypeOf(int16(0)),
reflect.Int32: reflect.TypeOf(int32(0)),
reflect.Int64: reflect.TypeOf(int64(0)),
reflect.Uint: reflect.TypeOf(uint(0)),
reflect.Uint8: reflect.TypeOf(uint8(0)),
reflect.Uint16: reflect.TypeOf(uint16(0)),
reflect.Uint32: reflect.TypeOf(uint32(0)),
reflect.Uint64: reflect.TypeOf(uint64(0)),
reflect.String: reflect.TypeOf(""),
}
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |