My code to read back a user is
func ReadUser(c appengine.Context, query *datastore.Query) ([]User, error) {
q := query.Run(c)
var results []User
var result User
for {
_, err := q.Next(&result)
if err == datastore.Done {
break
}
if err != nil {
return nil, err
}
results = append(results, result)
}
return results, nil
}
Rather than repeat all that for every different type, I want to do
something like
func Read(c appengine.Context, query *datastore.Query, result interface{},
results []interface{}) ([]interface, error) {
q := query.Run(c)
for {
_, err := q.Next(&result)
if err == datastore.Done {
break
}
if err != nil {
return nil, err
}
results = append(results, result)
}
return results, nil
}
but I can't figure out how to give the q.Next a concrete type so that
datastore knows
how to read in the data.
I've tried looking at reflection and type switches, but end up having to
repeat the code
multiple times.
Please could someone point me in the correct direction.
Many thanks
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.