连接到AppEngine开发环境中的Cloud Datastore API。

huangapple go评论91阅读模式
英文:

Connecting to AppEngine datastore in development via Cloud Datastore API

问题

我们目前正在运行一个结合了AppEngine和GCE的应用程序,到目前为止,我们所有的数据存储访问都是在AppEngine端进行的。现在,我们正在探索允许我们的GCE实例对(共享的)数据存储进行一些查询。首先,我正在尝试弄清楚如何在本地运行。我们目前的情况如下:

  • 运行一个Go devappserver
  • 一个希望向devappserver数据存储发出查询的Go独立二进制文件。
  • 我们安装了('go get')google-api-go-client/datastore/v1beta2,以便我们可以使用API而不是直接发出HTTP调用。然而,如果这个API库在开发中无法工作,我们肯定愿意发出直接的HTTP调用。
  • 我们已经设置了服务账号(我们已经从GCE访问GCS),但我怀疑这对于在本地运行来说并不相关...

我看过一些文档,但它们(a)只讨论Python和Java,(b)讨论连接到(独立的)开发数据存储服务器,而不是嵌入在AppEngine的devappserver中的数据存储(如果它们真的不同的话)。这里还有一个StackOverflow上的答案,但它再次讨论连接到独立的开发数据存储服务器:

https://stackoverflow.com/questions/21703006/how-to-connect-to-the-local-google-cloud-storage-datastore-db/21735913#21735913

任何指导都将不胜感激!

  • Ian
英文:

We are currently running a combined AppEngine / GCE app and thus far have kept all of our datastore access on the AppEngine side of things. Now we are exploring also allowing our GCE instance to make some queries into the (shared) datastore. To start, I'm trying to figure out how to run things locally. What we have so far:

  • A Go devappserver running
  • A Go standalone binary that wants to issues queries to the devappserver datastore.
  • We installed ('go get') google-api-go-client/datastore/v1beta2 so that we can use an API instead of issuing direct HTTP calls. However we are definitely willing to issue direct HTTP calls if this API library won't work in development.
  • We have service accounts set up (we already access GCS from GCE) but I doubt that's relevant for running locally...

I've seen some docs but they (a) only talk about Python & Java, and (b) discuss connecting to the (standalone) development datastore server, as opposed to the datastore embedded in AppEngine's devappserver (if those are even different?). There is also the following answer here on StackOverflow, but again it discusses connecting to the standalone development datastore server:

https://stackoverflow.com/questions/21703006/how-to-connect-to-the-local-google-cloud-storage-datastore-db/21735913#21735913

Any pointers would be much appreciated!

  • Ian

答案1

得分: 4

目前由于几个原因,在开发环境中还无法实现这一点。Google Cloud Datastore工具(gcd.sh)使用的是Java开发服务器。然而,在开发App Engine的Go应用程序时,使用的是Python开发服务器,其底层存储方式不同。在github页面上有一个跟踪此问题的bug。

但是,您仍然可以使用Go开发Google Cloud Datastore应用程序,但是当前的Go客户端库中存在许多错误。不幸的是,开发服务器目前不支持Go库使用的JSON API(请参阅页面顶部的注释)。

更新:我想确保将proppy的评论作为答案的一部分展示出来。他的建议提供了一种使用API的协议版本的方法,这可能比上述的Go客户端库更稳定。它还可以让您使用gcd.sh工具在开发服务器中进行测试。但是,您将不得不自己构建HTTP请求,并且无法在应用程序和开发中的Cloud Datastore之间共享数据。然而,这绝对是一个很好的解决方法,并且可以让您使用Cloud Datastore API,随着其发展,使用起来将比其他解决方法更容易。
来自proppy的建议:
>请注意,您仍然可以使用Go使用Cloud Datastore Protobuf HTTP API。Protobuf定义可在GitHub上找到,您可以使用Go protobuf编译器插件将其编译为Go代码,然后将POST HTTP请求发送到/datastore/{version}/datasets/{datasetId}/{method}

英文:

Currently this is not possible in the development environment for several reasons. The Google Cloud Datastore tool (gcd.sh) uses the java development server. However when developing go for App Engine you use the python development server, which has different underlying storage. There is a bug to track this issue on the github page.

You can still develop a Google Cloud Datastore application in go however there are many bugs in the current go client library. Unfortunately, the development server does not currently support the JSON API, which the go library uses (see the note at the top of the page).

Update: I wanted to make sure proppy's comment was seen as part of the answer. His suggestion does provide a way to use the protocol version of the API, which is probably more stable than the go client library above. It could also let you use the gcd.sh tool to test this in the development server. You will have to craft the HTTP requests yourself though, and you won't be able to share the data in the datastore between your application and the Cloud Datastore in development. However it is definitely a good workaround and lets you use the Cloud Datastore API, which as it develops will be easier to work with than other workarounds.
From proppy:
>Note that you can still use Cloud Datastore Protobuf HTTP API with Go. The protobuf definition is available on GitHub, you can compile it to Go code using the Go protobuf compiler plugin and then send POST HTTP requests to /datastore/{version}/datasets/{datasetId}/{method}.

答案2

得分: 0

如果您的“GO”应用服务器的用例足够简单,您可以通过使用 API 调用访问您的 GAE 服务来实现访问(可能需要扩展服务以接收 API 调用)。

这样做的额外好处是,如果您的数据存储定义或函数发生更改,只需在一个地方进行更改即可。

英文:

If the use case from your "GO" app server is straight forward enough, you may want to implement access by using an API call to your GAE service (perhaps extending the service to receive the API calls).

This has the added benefit of only having to make changes in one place if your datastore definitions or functions change.

huangapple
  • 本文由 发表于 2014年2月19日 04:45:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/21864925.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定