<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 "net/http"? Do they offer some benefit I don'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'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 "net/http"?</p>
</blockquote>
<p>Because "net/http" <a href="https://github.com/julienschmidt/go-http-routing-benchmark">isn'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't used websockets in a while, x/net's websocket implementation left a lot to be desired.</p>
<p>It'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'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'll sometimes release a library -- this is where Gorilla and httprouter came from.</p>
<p>It's not a dig on Go'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's not like it'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 "net/http" isn'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's a good thing it'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 "zero allocations".</p></pre>Growlizing: <pre><p>I agree. I use the third parties so I don't have to manually setup path-params and do <code>if req.Method == "POST" {</code> type stuff.</p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传