Home >Backend Development >Golang >Connect to Google Cloud Datastore using dev_appserver.py and google.golang.org/
php editor Strawberry will introduce you how to use dev_appserver.py and google.golang.org/ to connect to Google Cloud Datastore. dev_appserver.py is a development server that can simulate the Google App Engine environment, while google.golang.org/ is an official code library of the Go language. Using the two together, you can easily connect to Google Cloud Datastore and read and write data. In this article, we will explain the specific steps in detail to help you get started quickly and successfully connect to Google Cloud Datastore.
Just as the title says. We have an older Go 1.11 AppEngine API that requires dev_appserver.py
to run. In short, I want appengine.Main()
and appengine.NewContext(r)
to allow my application to point to me using my project-id
Cloud data storage instead of local simulator storage. I set GOOGLE_APPLICATION_CREDENTIALS
to no avail.
This way I can run the server locally while accessing the shared cloud database.
I'm using google.golang.org/[email protected]
and dev_appserver.py --enable_console --port=8081 --support_datastore_emulator=true --go_debugging=true app.yaml
is it possible? Or am I stuck on the local emulator when using the old Go library?
Move from comments to answers
View go 1.11’s remote_api
https://www.php.cn/link/2d680487650d66445b50d3d759eccad4
The logic of using it is similar to -
If running in local environment, use remote_api
Otherwise stick to default behavior (i.e. since remote_api
is not enabled, it will use emulator in local environment or directly in production Using production data)
For simplicity, you can try using the same variable name, i.e.
if this is local environment ctx, err := remote_api.NewRemoteContext(host, hc) else ctx := appengine.NewContext(r)
You then use "ctx" in the rest of your queries/calls to the datastore
NOTE: I am not familiar with "go" so consider the above as pseudocode rather than working code
You may also want to consider running the above changes without the --support_datastore_emulator=true
flag
The above is the detailed content of Connect to Google Cloud Datastore using dev_appserver.py and google.golang.org/. For more information, please follow other related articles on the PHP Chinese website!