<p>The service I'm planning on making is pretty simple, it's basically just taking input, requesting data from an API and returning what it gets.
Go services for App Engine can't use the "main" package from what I understand, so I don't think it can be as simple as just putting everything in one package, there needs to be some separation.</p>
<p>From reading the App Engine guides, it also seems that since it has to make calls to the internet, it needs to use appengine's HTTP client, which further complicates the situation.</p>
<p>My thought (which I think should probably work, I'm still in the planning phase so I'm not 100% sure) was basically making 2 separate "frontends", one for the appengine server and one for the standalone server, and put all the service logic in it's own package, and abstract any functions I need to use from appengine into both server packages so the main service logic doesn't have to worry about them. I think this would probably work, but I think it might complicate the code and doesn't seem very elegant.</p>
<p>Is there any better way to do this? It seems like something somebody must have done before, but I can't find anything similar from my searching.</p>
<hr/>**评论:**<br/><br/>CaptaincCodeman: <pre><p>I normally use build tags for this - have a standalone file that contains the main func and another that does the appengine setup.</p>
<p>Here's an example (also includes using MongoDB vs datastore):
<a href="https://github.com/CaptainCodeman/clean-go" rel="nofollow">https://github.com/CaptainCodeman/clean-go</a></p>
<p>Look in the app folder for the standalone vs appengine entry points.</p></pre>Hakkin: <pre><p>This looks exactly like what I was looking for, thanks! My friend had actually mentioned build tags, but he said he didn't think App Engine provided one, so I didn't look into it further, guess I should have!</p></pre>broady: <pre><p>"appengine" is the build tag for standard, "appenginevm" for flexible.</p>
<p>Most Go apps should "just work" on app engine flexible. But there are several trade-offs between standard and flexible.</p>
<p>Disclaimer: I work on Go on Google Cloud, including App Engine toolchain</p></pre>echophant: <pre><p>CaptaincCodeman's answer is great, and another option you can consider is <a href="https://cloud.google.com/appengine/docs/flexible/go/quickstart" rel="nofollow">App Engine Flex</a>. It's in Beta at the moment, so I wouldn't use it for a critical production service, but you write a normal Go application that you can run with <code>go run</code> and uses all of the standard <code>cloud.google.com/go/...</code> packages. Then it gets packaged up into a Docker container and deployed.</p></pre>tmornini: <pre><p>Can GAE use Docker containers?</p>
<p>If so, a single container would serve both purposes and likely remove the main package limitation as well.</p></pre>
Best way to go about implementing service that can be run as either a standalone server or on Google App Engine?
blov · · 570 次点击这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传