简体   繁体   中英

Connect to Google Cloud Datastore using dev_appserver.py & google.golang.org/appengine@v1.6.6

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/appengine@v1.6.6 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?

Moving from comments to answer

  1. Take a look at remote_api for Go 1.11 https://cloud.google.com/appengine/docs/legacy/standard/go111/tools/remoteapi

  2. The 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 (ie since remote_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 ie

    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

  3. You might also want to consider not running the above changes with the --support_datastore_emulator=true flag

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM