Yes.
For inserts you can implement the db.driver.Valuer interface
import "database/sql/driver"
func (p Point) Value() (driver.Value, error) {
//Assuming that p.String() returns a correctly formatted string
return p.String(), nil
}
db.Exec("insert into x (point) values(ST_GeometryFromText(?, 4326))", point)
Of course, you can also skip the Valuer interface and just do:
db.Exec("insert into x (point) values(ST_GeometryFromText(?, 4326))", point.String())
but the former looks nicer. I would take this a step further and use a trigger
to centralize the conversion so the sql looks like:
db.Exec("insert into x (point) values(?)", point)
For scanning, you'd need to implement the db.Scanner interface.
func (p *Point) Scan(val interface{}) error {
// parse []byte into Point members
}
-Gyepi