合并独立的Web应用和Go语言的GAE

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

Merge standalone webapp and GAE in Go

问题

我正在开发一个非常简单的Web应用程序,使用Go语言编写。
我有一个独立版本,现在要将其移植到GAE。看起来只有很小的变化,主要涉及数据存储API(在独立版本中只需要文件)。
我还需要包含appengine包,并使用init()代替main()。

有没有简单的方法将两个版本合并?由于Go语言中没有预处理器,所以似乎我必须为独立版本编写一个与GAE兼容的API,并在独立构建中使用这个模拟模块,而在GAE版本中使用真实的API。但对我来说,这听起来有点过度设计。

另一个问题是,GAE可能使用较旧的Go版本(例如,最新的Go发布版本使用新的模板包,但GAE使用较旧的版本,它们不兼容)。那么,在构建时或运行时是否有任何处理这种差异的方法?

谢谢,
Serge

更新:现在GAE使用与稳定独立编译器相同的Go版本(r60),所以抽象层次现在非常简单。

英文:

I'm working on a very simple web app, written in Go language.
I have a standalone version and now port it to GAE. It seems like there is very small changes, mainly concerning datastore API (in the standalone version I need just files).
I also need to include appengine packages and use init() instead of main().

Is there any simple way to merge both versions? As there is no preprocessor in Go, it seems like I must write a GAE-compatible API for the standalone version and use this mock module for standalone build and use real API for GAE version. But it sounds like an overkill to me.

Another problem is that GAE might be using older Go version (e.g. now recent Go release uses new template package, but GAE uses older one, and they are incompatible). So, is there any change to handle such differences at build time or on runtime?

Thanks,
Serge

<b>UPD:</b> Now GAE uses the same Go version (r60), as the stable standalone compiler, so the abstraction level is really simple now.

答案1

得分: 3

以广义来说,使用抽象化。为持久化提供接口,并编写两个实现,一个基于数据存储,一个基于本地文件。然后,为每个平台编写一个单独的主/初始化模块,该模块实例化适当的持久化接口,并将其传递给主应用程序以使用。

英文:

In broad terms, use abstraction. Provide interfaces for persistence, and write two implementations for that, one based on the datastore, and one based on local files. Then, write a separate main/init module for each platform, which instantiates the appropriate persistence interface, and passes it to your main application to use.

答案2

得分: 1

我的直接答案是(如果你想同时维护GAE和非GAE版本),你可以使用一个可靠的版本控制系统,比如git或hg,并为每个版本维护单独的分支。GAE API与Go相当契合,所以不应该有太多的改变。

至于不同版本的问题,你应该在GAE版本中维护代码,并使用gofix(不幸的是只能单向转换)来生成与发布兼容的版本。唯一可能会引起麻烦的地方是如果你使用了正在被弃用的template包;如果有必要,你可以在GAE包中包含新的template包。

如果你最终得到了你不想在Google服务器上运行的GAE代码,你还可以考虑使用AppScale

英文:

My immediate answer would be (if you want to maintain both GAE and non-GAE versions) that you use a reliable VCS which is good at merging (probably git or hg), and maintain separate branches for each version. The GAE API fits in reasonably well with Go, so there shouldn't be too many changes.

As for the issue of different versions, you should probably maintain code in the GAE version and use gofix (which is unfortunately one-way) to make a release-compatible version. The only place where this is likely to cause trouble is if you use the template package, which is in the process of being deprecated; if necessary you could include the new template package in your GAE bundle.

If you end up with GAE code which you don't want to run on Google's servers, you can also look into AppScale.

huangapple
  • 本文由 发表于 2011年9月25日 19:36:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/7545243.html
匿名

发表评论

匿名网友

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

确定