Handle ValueTranscoder EncodeTo returns error on bad type
Instead of panicking
This commit is contained in:
@@ -55,9 +55,15 @@ func decodePointFromText(mr *pgx.MessageReader, size int32) interface{} {
|
||||
return p
|
||||
}
|
||||
|
||||
func encodePoint(w *pgx.MessageWriter, value interface{}) {
|
||||
p := value.(Point)
|
||||
func encodePoint(w *pgx.MessageWriter, value interface{}) error {
|
||||
p, ok := value.(Point)
|
||||
if !ok {
|
||||
return fmt.Errorf("Expected Point, received %T", value)
|
||||
}
|
||||
|
||||
s := fmt.Sprintf("point(%v,%v)", p.x, p.y)
|
||||
w.Write(int32(len(s)))
|
||||
w.WriteString(s)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user