Categories
Mastering Development

Facing issue querying google datastore

Here’s the part of the code

var Ctx = context.Background()
DSClient, err := datastore.NewClient(Ctx, PROJECT_ID)
if err != nil {
    log.Fatal("Couldn't connect to DataStore: ", err)
}
log.Print("DataStore Client: ", DSClient)
q := datastore.NewQuery("users").Filter("email=", greq.Email).Limit(1)
keys, err := config.DSClient.GetAll(config.Ctx, q, &urs)

I’m getting following error.

http: panic serving 127.0.0.1:60844: runtime error: invalid memory address or nil pointer dereference
goroutine 20 [running]:
net/http.(*conn).serve.func1(0xc0002ee640)
    /home/shwetanka/tools/go/src/net/http/server.go:1767 +0x139
panic(0x9d1c00, 0xf80450)
    /home/shwetanka/tools/go/src/runtime/panic.go:679 +0x1b2
cloud.google.com/go/datastore.(*Client).Run(0x0, 0xb7b8e0, 0xc0002e5020, 0xc000117788, 0xb86420)
    /home/shwetanka/go/pkg/mod/cloud.google.com/go/datastore@v1.1.0/query.go:580 +0x167
cloud.google.com/go/datastore.(*Client).GetAll(0x0, 0xb7b860, 0xc0000380f0, 0xc000117788, 0x96e8e0, 0xc0002de5c0, 0x0, 0x0, 0x0, 0x0, ...)
    /home/shwetanka/go/pkg/mod/cloud.google.com/go/datastore@v1.1.0/query.go:520 +0x173

Logging the client gives this. So client is created.

DataStore Client: &{0xc0002e2010 0xc0002e41e0 PROJECT_ID}

err is nil. I don’t get any error in DSClient initialization. While querying I’m getting nil pointer reference. What could be the possible reasons for this?

Leave a Reply

Your email address will not be published. Required fields are marked *