2
0

Handle ValueTranscoder EncodeTo returns error on bad type

Instead of panicking
This commit is contained in:
Jack Christensen
2014-06-19 08:03:14 -05:00
parent 5fe3dd7ecf
commit 884252675e
4 changed files with 144 additions and 33 deletions
+8 -2
View File
@@ -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
}