I built a small go app, for use in AppEngine. I run the go locally through go run .., and I am trying to use the datastore.
I run the datastore emulator locally through gcloud beta emulators datastore start and by exporting DATASTORE_EMULATOR_HOST the go app can locally connect to it.
So I built my app using cloud.google.com/go/datastore, but when I deployed this to AppEngine any go code that connects to the datastore seems to make the whole app fail with a timeout.
Whilst trying to debug this I ran into code using google.golang.org/appengine/datastore and writing some test code I got things to work on AppEngine.
However this datastore does not seem to be able to connect to the datastore emulator.
- Has anyone run into the timeout issue when using
cloud.google.com/go/datastore? I seem to read on different answers that people say to use this package and not the golang.org package for some reason. - Can I use
cloud.google.com/go/datastoreon AppEngine? I would prefer to use this package, since it works with the datastore emulator.
I am using the following code, in short:
import "cloud.google.com/go/datastore"
...
ctx := appengine.NewContext(r)
...
client, err := datastore.NewClient(dsCtx, projectID)
...
key := datastore.IDKey(TestKind, testID, nil)
err = client.Get(ctx, key, &data)
This is the code that times out on AppEngine, but works fine locally.
The code that likewise works on AppEngine is this:
import "google.golang.org/appengine/datastore"
...
ctx := appengine.NewContext(r)
key := datastore.NewKey(ctx, TestKind, "", testID, nil)
err := datastore.Get(ctx, key, &data)
And this will fail locally with the following:
Metadata fetch failed: Get http://metadata/computeMetadata/v1/instance/attributes/gae_project: dial tcp: lookup metadata: no such host
Any help would be much appreciated.