Does anyone think that using a web framework in golang is trivial when you can just make a web app out of net/http?

xuanbao · · 263 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>Of course, you can&#39;t go wrong complementing with gorilla/mux.</p> <hr/>**评论:**<br/><br/>hobbified: <pre><p>I think that anyone who thinks that has never written a serious application in their life. There&#39;s no &#34;just&#34; about it, it&#39;s a shitton of work, and wisdom says not to reinvent any more wheels than necessary.</p></pre>brute0112358: <pre><p>Yes, a shitton of work that is trivial. And when it&#39;s trivial, I doubt it&#39;s even written as a serious application. </p></pre>hobbified: <pre><p>Trivial work is for computers, non-trivial work is for programmers.</p></pre>brute0112358: <pre><p>Spare me your wisdom but I think you&#39;re clearly off to my point though about why web frameworks in Go are trivial. You think that it&#39;s non-trivial because it was written really seriously. How? What are they trying to solve when an existing solution already exists in net/http and god knows the Golang team would improve it. And you&#39;re not even trying to explain to me why a particular web framework in Go should be used or net/http is lacking something.</p></pre>hobbified: <pre><p>No, honestly I have no clue what you&#39;re even saying, you seem to be using &#34;trivial&#34; in a way that English speakers do not, and I don&#39;t have any interest in even trying to follow if the only purpose is going to be to insult me.</p></pre>brute0112358: <pre><p>I fail to see my replies here are an insult to you. And what should be an alternative word then, &#34;useless&#34;? That&#39;s even more of an insult to me. If you think this kind of discussion upsets you and you wanna avoid it, then stop trolling on Reddit.</p></pre>darklumt: <pre><p>Please tell me how trivial and easy is to implement proper caching, cookies, sessions, multiple users with proper auth, redirects, permissions and what not with only net/http, and doing it every single time for each project.</p> <p>ORM&#39;s libraries and frameworks are just tools that allow you to focus on the important work, you dont have to use them, and sometimes its better to not use to, but dont reinvent the wheel , because most of the time you actually dont have to.</p> <p>Building an REST API with net/hhtp and maybe your favorite router, sure why not, its going to keep it pretty clean and simple but outside of that, the mentality of only using the std lib goes out of scope IMO.</p></pre>hutilicious: <pre><p>i prefer using net/http just to be as lightweight as possible ?</p></pre>brute0112358: <pre><p>Which is why I&#39;m trying to convey here. Why use web framework to build even a simple REST API server when you already have the net/http package.</p></pre>aboukirev: <pre><p>Oh, are you talking REST API or Web application? With full Web application, even 2-3 pages, you&#39;d have to support OPTIONS verb, proper caching headers, compression, and a few more nitty-gritty details. A nice micro-framework does it for you or helps you to be a good netizen.</p></pre>brute0112358: <pre><p>It&#39;s nice to have a framework that does all the work with you whether it&#39;s lightweight or with batteries included, but over time when a web application scales, you want to have a full control of which compression library or other nitty-gritty details that works some particular use cases to the web application. Of course, someone can fork and inspect the source code of the web framework but it definitely beats the whole purpose of having a web framework. </p> <p>I might be wrong here but in Go, it&#39;s far more common to integrate libraries than frameworks.</p></pre>aboukirev: <pre><p>There is a fine line between library and framework. Some call Gorilla Toolkit a set of libraries. It could be called a framework too. It&#39;s especially difficult to tell with router libraries where you plug your handlers into the framework.</p> <p>The discussion started with <code>net/http</code> or framework, i.e. no 3rd party or with 3rd party. </p></pre>Glensarge: <pre><p>Yeah I just use httprouter for mux n write everything else myself. I feel like if you&#39;re going down the rabbit hole of frameworks you&#39;re sort of ignoring the point of go and it&#39;s keep-everything-simple and small mentality? Maybe im wrong</p> <p>Regardless of that though doing everything yourself is so easy it doesn&#39;t make that much of a difference, you just reduce overheads</p></pre>brute0112358: <pre><p>Most of the time, frameworks hide in exchange of over-simplicity, elegance and magic. The net/http handler functions already expose the necessary http.Request and http.Response but frameworks like Echo hide them and instead, provide you a Context handler. These web frameworks don&#39;t give you immediately the opportunity how basic request-response architecture works and it becomes harder when any developer integrates more packages.</p></pre>TheMerovius: <pre><blockquote> <p>Of course, you can&#39;t go wrong complementing with gorilla/mux.</p> </blockquote> <p><a href="https://blog.merovius.de/2017/06/18/how-not-to-use-an-http-router.html" rel="nofollow">I disagree</a></p></pre>brute0112358: <pre><p>Care to explain more? Then by using only net/http, how would you implement a parameterized route? I&#39;m interested on how you would come up with.</p></pre>brute0112358: <pre><p>I read your post and I disagree on what you&#39;re trying to make. It adds more complexity to your code and many developers prefer a simple style that immediately reveals to them what services/controllers they&#39;re developing with in relation to a particular route. In other words, they want to see &#34;foo/bar&#34; immediately to their eyes. If I change the structure of my paths, then I have to change your Mux logic. If I&#39;m in a team of developers, then someone should be assigned to maintain how the routes structured and how they worked. </p> <p>You should definitely add a way to comment your posts on your blog.</p></pre>TheMerovius: <pre><blockquote> <p>I read your post and I disagree on what you&#39;re trying to make.</p> </blockquote> <p>That&#39;s fine :)</p> <blockquote> <p>You should definitely add a way to comment your posts on your blog.</p> </blockquote> <p>Unfortunately, I can&#39;t really justify the toil that moderating that would require, so I intentionally left it out. You can find some of the discussion of this particular post (including my opinions/retorts on the point you are bringing up) <a href="https://www.reddit.com/r/golang/comments/6i22tm/how_not_to_use_an_httprouter_in_go/" rel="nofollow">in this reddit thread</a>.</p></pre>

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

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