Why use 3rd party mux?

polaris · · 548 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>I am new to Go and learning by following some examples for web server development. I came across solutions like Negroni, Gorilla mux and some other options. However I have difficulty understanding why do we need these when we already have &#34;net/http&#34;? Do they offer some benefit I don&#39;t understand? </p> <hr/>**评论:**<br/><br/>gohacker: <pre><p>Some of them extract URL parts for you (<code>/api/v1/users/:id</code>), some add a context to handlers.</p></pre>notathrowaway9988: <pre><p>I agree, both of those behaviors I find handy and are reasons I consider a 3rd party mux for web apps that aren&#39;t super trivial.</p></pre>alexfiori: <pre><p>+1</p></pre>newimprovedoriginal: <pre><p>routing hotness is also why i use httprouter or echo</p></pre>barsonme: <pre><blockquote> <p>why do we need these when we already have &#34;net/http&#34;?</p> </blockquote> <p>Because &#34;net/http&#34; <a href="https://github.com/julienschmidt/go-http-routing-benchmark">isn&#39;t as performant</a> as some third party libraries.</p> <p>Also, some libraries like Gorilla make implementing sessions and cookies a bit easier, and although I haven&#39;t used websockets in a while, x/net&#39;s websocket implementation left a lot to be desired.</p> <p>It&#39;s not that net/http is <em>bad</em>, but that the main contributors to Go have spent the majority of their time working on other parts of the language and haven&#39;t spent as much time optimizing and profiling the standard libraries.</p> <p>When other groups of people come in and through repeated use notice a deficiency, they&#39;ll sometimes release a library -- this is where Gorilla and httprouter came from.</p> <p>It&#39;s not a dig on Go&#39;s core contributors, but they have bigger things to tackle than net/http being slower or more difficult to use than it should be. And it&#39;s not like it&#39;s <em>bad</em> -- it works very well and you could totally only use net/http without any side effects.</p></pre>robertmeta: <pre><blockquote> <p>Because &#34;net/http&#34; isn&#39;t as performant as some third party libraries.</p> </blockquote> <p>The endless performance tweaking over mux seems borderline ridiculous for most real world uses and seems to an odd case of compulsive bikeshedding in the community.</p></pre>barsonme: <pre><blockquote> <p>an odd case of compulsive bikeshedding</p> </blockquote> <p>Yeah. Maybe. But it&#39;s a good thing it&#39;s random community members doing it and not me at my job :-)</p></pre>elithrar_: <pre><blockquote> <p>The endless performance tweaking over mux seems borderline ridiculous for most real world uses and seems to an odd case of compulsive bikeshedding in the community.</p> </blockquote> <p>And, in some cases, race conditions and memory sharing issues in the race for &#34;zero allocations&#34;.</p></pre>Growlizing: <pre><p>I agree. I use the third parties so I don&#39;t have to manually setup path-params and do <code>if req.Method == &#34;POST&#34; {</code> type stuff.</p></pre>

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

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