So, I misunderstood the API of Select, and didn't realize it was always expecting a slice... and so I passed it a pointer to a struct, figuring it would realize it was a struct and just do one row.... I got back a really ugly panic:
reflect.(_rtype).Elem(...)
/home/nate/go/src/pkg/reflect/type.go:584 +0x118
github.com/jmoiron/sqlx.StructScan(...)
/home/nate/code/go/src/github.com/jmoiron/sqlx/sqlx.go:761 +0x1b4
github.com/jmoiron/sqlx.Select(...)
/home/nate/code/go/src/github.com/jmoiron/sqlx/sqlx.go:508 +0xbe
github.com/jmoiron/sqlx.(_DB).Select(...)
/home/nate/code/go/src/github.com/jmoiron/sqlx/sqlx.go:160 +0x71
There seem to be a couple ways to handle this with better results:
1.) Allow this to work, just check to see if the thing passed in is a struct, and if so, just scan the first returned row
2.) Don't allow it to work, but handle the error with a more friendly error message
for #2, it might also be beneficial to rename the parameter as something like dest_slice ... to make it a little more obvious that it requires a slice.
So, I misunderstood the API of Select, and didn't realize it was always expecting a slice... and so I passed it a pointer to a struct, figuring it would realize it was a struct and just do one row.... I got back a really ugly panic:
reflect.(_rtype).Elem(...)
/home/nate/go/src/pkg/reflect/type.go:584 +0x118
github.com/jmoiron/sqlx.StructScan(...)
/home/nate/code/go/src/github.com/jmoiron/sqlx/sqlx.go:761 +0x1b4
github.com/jmoiron/sqlx.Select(...)
/home/nate/code/go/src/github.com/jmoiron/sqlx/sqlx.go:508 +0xbe
github.com/jmoiron/sqlx.(_DB).Select(...)
/home/nate/code/go/src/github.com/jmoiron/sqlx/sqlx.go:160 +0x71
There seem to be a couple ways to handle this with better results:
1.) Allow this to work, just check to see if the thing passed in is a struct, and if so, just scan the first returned row
2.) Don't allow it to work, but handle the error with a more friendly error message
for #2, it might also be beneficial to rename the parameter as something like dest_slice ... to make it a little more obvious that it requires a slice.