Best way to go about implementing service that can be run as either a standalone server or on Google App Engine?

blov · · 595 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>The service I&#39;m planning on making is pretty simple, it&#39;s basically just taking input, requesting data from an API and returning what it gets. Go services for App Engine can&#39;t use the &#34;main&#34; package from what I understand, so I don&#39;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&#39;s HTTP client, which further complicates the situation.</p> <p>My thought (which I think should probably work, I&#39;m still in the planning phase so I&#39;m not 100% sure) was basically making 2 separate &#34;frontends&#34;, one for the appengine server and one for the standalone server, and put all the service logic in it&#39;s own package, and abstract any functions I need to use from appengine into both server packages so the main service logic doesn&#39;t have to worry about them. I think this would probably work, but I think it might complicate the code and doesn&#39;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&#39;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&#39;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&#39;t think App Engine provided one, so I didn&#39;t look into it further, guess I should have!</p></pre>broady: <pre><p>&#34;appengine&#34; is the build tag for standard, &#34;appenginevm&#34; for flexible.</p> <p>Most Go apps should &#34;just work&#34; 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&#39;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&#39;s in Beta at the moment, so I wouldn&#39;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>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

595 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传