As the title says. We have a legacy Go 1.11 AppEngine API that requires the dev_appserver.py
to run. Simply, I want appengine.Main()
& appengine.NewContext(r)
to allow my application to point to my Cloud Datastore using my project-id
, rather than the local emulator's storage. I have set GOOGLE_APPLICATION_CREDENTIALS
to no avail.
This would be so I can locally run the server, while accessing a shared, Cloud DB.
I am using google.golang.org/[email protected]
w/ dev_appserver.py --enable_console --port=8081 --support_datastore_emulator=true --go_debugging=true app.yaml
Is this possible? Or am I stuck on a local emulator when using the old Go libraries?
CodePudding user response:
Moving from comments to answer
Take a look at
remote_api
for Go 1.11 https://cloud.google.com/appengine/docs/legacy/standard/go111/tools/remoteapiThe logic for using it would be something along the lines of -
If running on local environment, use
remote_api
else stick to the default behavior (i.e. sinceremote_api
isn't enabled, it will either use the emulator in local environments or use production data directly in production)To keep things simple, you could try using same variable name i.e.
if this is local environment ctx, err := remote_api.NewRemoteContext(host, hc) else ctx := appengine.NewContext(r)
Then you use 'ctx' in the rest of your queries/calls to datastore
Note: I'm not familiar with 'Go' so take the above as pseudo-code and not working code
You might also want to consider not running the above changes with the
--support_datastore_emulator=true
flag