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 runtime error: invalid memory address or nil pointer dereference
goroutine 20 [running]:
    /home/shwetanka/tools/go/src/net/http/server.go:1767 +0x139
panic(0x9d1c00, 0xf80450)
    /home/shwetanka/tools/go/src/runtime/panic.go:679 +0x1b2*Client).Run(0x0, 0xb7b8e0, 0xc0002e5020, 0xc000117788, 0xb86420)
    /home/shwetanka/go/pkg/mod/ +0x167*Client).GetAll(0x0, 0xb7b860, 0xc0000380f0, 0xc000117788, 0x96e8e0, 0xc0002de5c0, 0x0, 0x0, 0x0, 0x0, ...)
    /home/shwetanka/go/pkg/mod/ +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 *