Use github.com/pkg/errors
This commit is contained in:
+8
-8
@@ -3,11 +3,11 @@ package pgtype
|
||||
import (
|
||||
"database/sql/driver"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"math"
|
||||
"strconv"
|
||||
|
||||
"github.com/jackc/pgx/pgio"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type Float8 struct {
|
||||
@@ -43,28 +43,28 @@ func (dst *Float8) Set(src interface{}) error {
|
||||
if int64(f64) == value {
|
||||
*dst = Float8{Float: f64, Status: Present}
|
||||
} else {
|
||||
return fmt.Errorf("%v cannot be exactly represented as float64", value)
|
||||
return errors.Errorf("%v cannot be exactly represented as float64", value)
|
||||
}
|
||||
case uint64:
|
||||
f64 := float64(value)
|
||||
if uint64(f64) == value {
|
||||
*dst = Float8{Float: f64, Status: Present}
|
||||
} else {
|
||||
return fmt.Errorf("%v cannot be exactly represented as float64", value)
|
||||
return errors.Errorf("%v cannot be exactly represented as float64", value)
|
||||
}
|
||||
case int:
|
||||
f64 := float64(value)
|
||||
if int(f64) == value {
|
||||
*dst = Float8{Float: f64, Status: Present}
|
||||
} else {
|
||||
return fmt.Errorf("%v cannot be exactly represented as float64", value)
|
||||
return errors.Errorf("%v cannot be exactly represented as float64", value)
|
||||
}
|
||||
case uint:
|
||||
f64 := float64(value)
|
||||
if uint(f64) == value {
|
||||
*dst = Float8{Float: f64, Status: Present}
|
||||
} else {
|
||||
return fmt.Errorf("%v cannot be exactly represented as float64", value)
|
||||
return errors.Errorf("%v cannot be exactly represented as float64", value)
|
||||
}
|
||||
case string:
|
||||
num, err := strconv.ParseFloat(value, 64)
|
||||
@@ -76,7 +76,7 @@ func (dst *Float8) Set(src interface{}) error {
|
||||
if originalSrc, ok := underlyingNumberType(src); ok {
|
||||
return dst.Set(originalSrc)
|
||||
}
|
||||
return fmt.Errorf("cannot convert %v to Float8", value)
|
||||
return errors.Errorf("cannot convert %v to Float8", value)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -119,7 +119,7 @@ func (dst *Float8) DecodeBinary(ci *ConnInfo, src []byte) error {
|
||||
}
|
||||
|
||||
if len(src) != 8 {
|
||||
return fmt.Errorf("invalid length for float4: %v", len(src))
|
||||
return errors.Errorf("invalid length for float4: %v", len(src))
|
||||
}
|
||||
|
||||
n := int64(binary.BigEndian.Uint64(src))
|
||||
@@ -171,7 +171,7 @@ func (dst *Float8) Scan(src interface{}) error {
|
||||
return dst.DecodeText(nil, srcCopy)
|
||||
}
|
||||
|
||||
return fmt.Errorf("cannot scan %T", src)
|
||||
return errors.Errorf("cannot scan %T", src)
|
||||
}
|
||||
|
||||
// Value implements the database/sql/driver Valuer interface.
|
||||
|
||||
Reference in New Issue
Block a user