英文:
Making a Go Webapp independent of Google App Engine
问题
这个问题是关于我正在开发的网页应用程序的,这是一个用Go语言编写的订阅阅读器。代码可以在http://github.com/matthewbauer/rivulet找到,但这不是回答问题所必需的。
我有一个用Go语言编写的网页应用程序,正在Google的App Engine上运行。它使用了通常的App Engine库,如datastore、memcache和user。
有没有办法让我的用户在不破坏App Engine兼容性的情况下运行这个应用程序?
Go现在提供了构建约束,根据目标构建平台来排除/包含文件:
// +build !appengine
所以,我知道这是可能的。但是,我最大的问题是我的库依赖于App Engine:datastore、memcache和user。我知道其他库提供了datastore和memcache,而且我可以自己实现user,但是我该如何封装它们?
我知道他们可以使用SDK设置一个开发服务器,但是对于一些用户来说可能太复杂了。我想要一个普通Go项目提供的单个可执行文件。这可能吗?
如果有任何示例存在,我还没有找到它们;任何独立于App Engine的网页应用程序的示例都将不胜感激。我可以通过示例来学习。
英文:
This question comes from working on my webapp, a feed reader written in Go. The code is available at http://github.com/matthewbauer/rivulet although that should not be necessary to answer the question.
I have a webapp written in Go that is running on Google's App Engine. It uses the usual common App Engine libraries like datastore, memcache, and user.
Is there any way to let my users run this app on their own without breaking App Engine compatibility?
Go now provides build constraints that exclude/include files based on target build platform:
// +build !appengine
So, I know that this is possible. But, my biggest problem is with my libraries that depend on App Engine: datastore, memcache, and user. I know other libraries provide datastore and memcache, and I can implement user on my own, but how would I go about wrapping it up?
I know that I can have them set up a development server with the SDK, but that might be too involved for some users. I want a single executable that normal Go projects provide. IS that possible?
If any examples exist, I haven't found them yet; any examples of App Engine independent webapps would be appreciated. I can learn by example.
答案1
得分: 4
你可能需要重构你的代码。
基本的原则是,无论你在哪里依赖于一个AppEngine包,都要为你使用它的方式定义自己的接口。这将允许你将应用程序与appengine库解耦。
一旦你定义了这些接口,你就可以开始提供满足这些接口的替代方案。你将能够插入任何满足这些接口的数据存储或内存缓存,你的应用程序将能够在appengine上运行,也可以作为独立应用运行。
英文:
You will probably have refactor your code.
The basic rule of thumb will be anywhere you depend on an AppEngine package define your own interface for the way you use it. This will allow you decouple the app from the appengine libraries.
Once you've defined those interfaces then you can start providing alternatives that satisfy the interfaces. You'll be able to plugin any Datastore or Memcache that satisfies the interfaces and your app will be able to both run on appengine or as a standalone with the alternatives.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论