RESTful API in App Engine - vanilla or framework?

blov · · 1161 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>I&#39;m new to Go, and would like to convert a simple node.js API backend to Go to take advantage of the cheaper rates on App Engine Standard...</p> <p>There seem to be a good number of REST / JSON API libraries or frameworks or whatever for Go, and most seem to confuse me a bit. My first impression is that Go already does what you&#39;d use Flask of Express for, out of the box.</p> <p>I&#39;m wondering if a simple backend for a single page app, with about a dozen or so endpoints and Firebase user auth warrants learning and using a framework, or will my life be easier if I stick to plain Go and factory libs?</p> <hr/>**评论:**<br/><br/>Floooof: <pre><p>Factory libs? Not sure what you mean by that. Use a straightforward routing library such as goji.io or gorilla/mux and it should be pretty simple. Add a framework only if you need one.</p></pre>s1gmoid: <pre><p>I meant standard libs.</p></pre>t4pczan: <pre><p>maybe just check it out: <a href="https://blog.merovius.de/2017/06/18/how-not-to-use-an-http-router.html" rel="nofollow">https://blog.merovius.de/2017/06/18/how-not-to-use-an-http-router.html</a></p> <p>and go vanilla :)</p></pre>s1gmoid: <pre><p>Hey, I really like this. ;) Thanks!</p></pre>gobwas: <pre><p>Why not use only standard library?</p></pre>kuznetsovin: <pre><p>Recently, I thought about it too. I selected framework Echo for my app.</p></pre>blackout24: <pre><p>I solved the same problem a couple of days ago. I have a straight forward nodejs backend that I was able to deploy to Google App Engine, by just adding 4-5 lines of app.yaml. I need to serve the API via https which comes out of the box with https://&lt;my-project&gt;.appspot.com. Unfortunately there is no way to use shared CPUs in flex environment so it&#39;s a lot more expensive than just deploying it in a container on a GCE micro instance. So I moved the backend to GCE micro instance and reserved a static IP and wrote a simple REST Server in Go that simply forwards the request to the GCE instance and sends the response. I used nothing fancy, basically just that:</p> <p><a href="https://thenewstack.io/make-a-restful-json-api-go/" rel="nofollow">https://thenewstack.io/make-a-restful-json-api-go/</a> </p> <p>Hint: You can&#39;t use the standard way to make HTTP requests you have to use urlfetch in GAE. <a href="https://cloud.google.com/appengine/docs/standard/go/issue-requests" rel="nofollow">https://cloud.google.com/appengine/docs/standard/go/issue-requests</a></p> <p>Somehow this feels like a hack but it does what I need and saves money.</p></pre>s1gmoid: <pre><p>I don&#39;t see how using GCE as a backend would be worth it. The whole point of moving to App Engine Standard would be to get rid of virtual machines entirely, while maintaining scalability.</p> <p>Thanks, this is a neat thing to know but it&#39;s not what I was interested in. ;)</p></pre>blackout24: <pre><p>Ahh I see the thing in my case was that my backend uses PhantomJS, which I use with node-horseman so I needed to call native code on some kind of compute instance anyway.</p></pre>JohnMcPineapple: <pre><p>A lot of the routing libraries work pretty much the same as the stdlib router, so there isn&#39;t much to learn (in addition to the fact that a router is only a really small piece of API anyway). The more &#34;complete&#34; frameworks impose restrictions and changes in addition to hiding away how things work, so I prefer to use the stdlib for most parts where I can; and use single-purpose libraries for anything else.</p> <p>Personally I use <a href="https://github.com/go-chi/chi" rel="nofollow">Chi</a> because it&#39;s convenient and because the routing is more sensible than the one from the stdlib router (e.g. routes not automatically matching all sub-routes without explicitly adding path variables).</p></pre>FatFingerHelperBot: <pre><p>It seems that your comment contains 1 or more links that are hard to tap for mobile users. I will extend those so they&#39;re easier for our sausage fingers to click!</p> <p><a href="https://github.com/go-chi/chi" rel="nofollow">Here is link number 1</a> - Previous text &#34;Chi&#34;</p> <hr/> <p><sup>Please</sup> <sup>PM</sup> <sup><a href="/u/eganwall" rel="nofollow">/u/eganwall</a></sup> <sup>with</sup> <sup>issues</sup> <sup>or</sup> <sup>feedback!</sup> <sup>|</sup> <sup><a href="https://reddit.com/message/compose/?to=FatFingerHelperBot&amp;subject=delete&amp;message=delete%20dwmv9ow" rel="nofollow">Delete</a></sup></p></pre>beowulf_71: <pre><p>Gorilla/mux seems to be the standard now. There are others, but there is an ORM library that includes gorilla/mux, and other nice capabilities (management of db, etc) that can easily handle this for you.</p></pre>govision: <pre><p>Are you planning on using this for that etherium stuff?</p></pre>

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

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