dongpao1083 2011-09-25 11:36
浏览 45
已采纳

在Go中合并独立的网络应用和GAME

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

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

  • 写回答

2条回答 默认 最新

  • duanji2002 2011-09-26 01:23
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?