Which Golang Packages to use for Google App Engine

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

Which Golang Packages to use for Google App Engine

问题

最近,我开始使用golang在App Engine上探索Google Identity Kit。我参考了googlesamples/identity-toolkit-go中的示例代码。在查看代码时,我发现了一些与App Engine相关的包:

"google.golang.org/appengine"
"google.golang.org/appengine/datastore"

对于我正在开发的GAE Golang应用程序,我使用GAE SDK通过goapp run来运行应用程序。然而,在我的代码中,我只引用了

"appengine"
"appengine/datastore"

因为这指向了提取的go appengine sdk中的golang源代码。

我是否需要使用google.golang.org的appengine包?

在意识到identity kit方法所期望的appengine.Context与我使用的不匹配之后,我才发现了这一点。我收到了以下错误信息:

`cannot use c (type "appengine".Context) as type "golang.org/x/net/context".Context in argument to client.ValidateToken. "appengine".Context does not implement "golang.org/x/net/context".Context (missing Deadline method)`

尽管我使用了appengine.NewContext(r),就像示例中解释的那样。

英文:

I recently started to explore the Google Identity Kit using golang on the App Engine. I was going off of the samples in the googlesamples/identity-toolkit-go. In looking at the code, I found some appengine packages for the following:

"google.golang.org/appengine"
"google.golang.org/appengine/datastore"

For the GAE Golang application that I am working on, I use the GAE SDK to run the application using goapp run. However, in my code, I only reference

"appengine"
"appengine/datastore"

because this points to the golang src located in the extracted go appengine sdk.

Do I need to be using the google.golang.org appengine packages instead?

I only found this out after realizing that the appengine.Context that is expected by the identity kit methods did not match what I was using. I received this error

`cannot use c (type "appengine".Context) as type "golang.org/x/net/context".Context in argument to client.ValidateToken. "appengine".Context does not implement "golang.org/x/net/context".Context (missing Deadline method)`

despite me using appengine.NewContext(r) as the example explained.

答案1

得分: 2

我建议如果可以的话,使用google.golang.org/appengine包。它们与语言更加兼容,主要是因为你提到的原因(contextnet/context),而且这些库更新且通常具有更多功能。特别是如果你计划使用其他Google服务(如Google Cloud Storage),使用这些更新的库会更加方便。

但是它们也更好,因为它们只是常规的可导入包,与标准的Go工具集(如自动格式化的goimports,自动补全的gocode等)更加兼容。

然而,它们并不完全完整。有一些功能是缺失或已弃用的。根据我的经验,以前主要缺失的功能是aetest包,但现在已经被移植了,所以现在几乎没有理由不切换了。

英文:

I recommend using the google.golang.org/appengine packages if you can. They play nicer with the language, primarily because of the reason you mention (context is a net/context), and also because the libraries are newer and often have more features. In particular if you plan to use other Google services (like Google Cloud Storage) you'll have a much easier time using the newer libraries.

But they're also better because - since they're just regular, importable packages - they play nicer with the standard set of go tools: goimports for auto-formatting, gocode for autocomplete, etc..

However they are not entirely complete. There are some features missing or deprecated. In my experience it used to be that the major missing feature was the aetest package, which has since been ported, so there's now very few reasons not to switch.

huangapple
  • 本文由 发表于 2015年11月30日 23:01:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/34001547.html
匿名

发表评论

匿名网友

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

确定