Is there a direct comparison of all those web frameworks?

blov · · 170 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>As already dicussed <a href="" rel="nofollow">here</a>, the amount of web framework for Go is pretty huge. Spontanously I can think of Beego, Gin, Buffalo, Echo and Revel, but I&#39;m sure there are even more. Personally I usually prefer having a framework over writing everything from scratch, but it&#39;s really hard to decide for one. Does anybody have a table-like comparison of Go web frameworks with focus on their features (and whether they&#39;re still maintained or not)? </p> <hr/>**评论:**<br/><br/>aboukirev: <pre><p>Besides the fairly universal speed benchmark like <a href="" rel="nofollow"></a> I have not seen any feature comparisons.</p> <p>One big difference in router type is that some routers require unique matches for a route (like <code>httprouter</code>, original <code>chi</code>). Others allow for multiple matches and utilize priority of some kind to pick the route: order of declaration or exact match is preferred over parameterized or wildcard (like <code>echo</code>).</p> <p>I have one Web application converted from Drupal where aliases (a fixed manually defined URL) were used for SEO purposes. Drupal first performs a lookup for an alias, translates to regular URL and only then passes that to router. I tried to do that in Go with custom middleware, custom handler, doing it in 404 handler (search alias when URL did not match any regular route). It was all ugly. Besides, it would make an extra database hit on most requests. I ended up using <code>echo</code>, loading aliases once on startup, and creating fixed routes that have highest priority. All in memory in a trie structure and routing is very fast.</p> <p>Before I picked <code>echo</code> I went through:</p> <ul> <li><p>pure <code>net/http</code></p></li> <li><p>Gorilla toolkit</p></li> <li><p><code>gin</code></p></li> <li><p><code>goji</code></p></li> <li><p><code>echo</code></p></li> </ul> <p>I could have stayed with <code>gin</code> except it was lagging in adopting standard <code>context</code> package at the time. AFAIK, <code>revel</code> stands out by doing everything in its own way, completely non-standard, non-idiomatic. To add convenience and accommodate passing parameters from route parsing many Web frameworks did one of the following:</p> <ul> <li><p>add an extra context parameter to all handlers</p></li> <li><p>extend request type (custom request)</p></li> <li><p>extend response type (custom response)</p></li> </ul> <p>&#34;Pure&#34; frameworks now utilize <code>context</code> to pass data around now (which is not what <code>context</code> was designed for) or provide utility methods to parse route and URL query again in the body of a handler. I am talking about the routes like <code>group1/group2/:id</code> where elements have been matched and &#39;:id&#39; parameter value parsed while routing and could have been immediately available to the handler except for the standard Handler and HandlerFunc having no way to pass that information in arguments.</p> <p>There is more, of course. Standard <code>net/http</code> does not define constants for some standard HTTP headers. Web frameworks introduce various convenience methods. All these things you can add in your own code. Frameworks also provide form binding and validation infrastructure, integrated logging, graceful shutdown, integration of template rendering (loading and caching templates), and some standard middleware: serving static content, CORS, sessions, etc. You can get those from separate 3rd party packages as well and typically frameworks just wrap 3rd party code. </p> <p>The bad news is you have to try a few solutions to decide what you want from a framework.</p></pre>Yojihito: <pre><blockquote> <p>loading aliases once on startup</p> </blockquote> <p>What does happen if I create a new blog entry with an alias? Do I need to restart the router then?</p></pre>aboukirev: <pre><p>It was for legacy routes. You can add dynamically routes in <code>echo</code> now while it&#39;s running. An alternative would be graceful restart.</p></pre>kamaleshbn: <pre><p>I&#39;ve seen this, but not exactly feature comparison. Still, a decent overview.</p> <p><a href="" rel="nofollow"></a></p> <p>Also this is something which I wrote, it&#39;s bare bones, and sticks to standard packages, including the signature of the handlers. </p> <p><a href="" rel="nofollow"></a></p></pre>

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

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