Should i write my next webapp in golang? If so, which framework would you recommend?

xuanbao · · 1105 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<hr/>**评论:**<br/><br/>dankcode: <pre><p>Stdlib is pretty awesome, also the standard library, also stdlib.</p></pre>_PM_ME_YOUR_PELVIS_: <pre><p>Just don&#39;t Google STD List when you want data structure details</p></pre>eygzus: <pre><p>Google knows me well enough to know that I have all of the information on STDs that I need. </p></pre>chuhnk: <pre><p>Just want to echo the sentiment of some here. Start with the stdlib; net/http, html/template and then pick and choose some lightweight helper libraries from there. </p></pre>lifter: <pre><p>Sure, Go could be a great choice for a web app, but I guess it depends on the scope.</p> <p>What kind of web app are you hoping to build?</p> <p>In terms of frameworks I&#39;ve tended to shy away from anything too elaborate and instead just lean on the stdlib + <a href="https://github.com/gorilla/mux" rel="nofollow">Gorilla Mux</a> (for richer routing) + <a href="https://github.com/codegangsta/negroni" rel="nofollow">Negroni</a> (some common/useful middleware).</p></pre>AnimalMachine: <pre><p>+1 agreed.</p> <p>stdlib + Gorilla Mux is what I&#39;ve used and I think that&#39;s about all you need.</p></pre>balloonanimalfarm: <pre><p>The core of Go is built around writing good web-apps, so it isn&#39;t like other languages where you <em>need</em> a framework to build things. Take a look at the <a href="https://golang.org/doc/articles/wiki/" rel="nofollow">building a webapp</a> tutorial. You&#39;ll write a Wiki in about 90 lines of code.</p> <p>There are a lot of middlewares that &#34;just work&#34; together because they follow Go&#39;s architecture. You could extend the Wiki by adding markdown support and basicauth in about 5 more lines of code.</p></pre>rek2gnulinux: <pre><p>you dont need a framework.. </p></pre>Grundlebuttskin: <pre><p>Write APIs in go using a lightweight mux library like goji, xmux or echo. Write the front-end in javascript using angular, react or whatever you know now. You can then serve the static front-end from a CDN and easily scale the stateless backend.</p></pre>newimprovedoriginal: <pre><p>echo is nice <a href="https://github.com/labstack/echo" rel="nofollow">https://github.com/labstack/echo</a></p></pre>bikbah: <pre><p>current version is v2-beta, so it is better to use stable v1 <a href="http://gopkg.in/labstack/echo.v1" rel="nofollow">http://gopkg.in/labstack/echo.v1</a></p></pre>cube2222: <pre><p>Just use stdlib (it&#39;s awesome in golang), a http router (like gorilla mux), and if you need to, but it&#39;s not really necessary, middleware like negroni. </p> <p>You can acomplish most things easily by using the stdlib.</p> <p>Big frameworks like martini/revel/gin aren&#39;t really idiomatic Go and aren&#39;t needed at all.</p></pre>MrSaints: <pre><p>I&#39;m not too sure about Martini, but I definitely wouldn&#39;t count Gin as a &#34;big framework&#34;. I&#39;d like to know why you think that&#39;s the case, and why you don&#39;t consider it to be idiomatic Go.</p></pre>cube2222: <pre><p>It&#39;s not much different than martini. It&#39;s just a one framework for everything. Sure it&#39;s much better than martini (a lot faster), but still, as they say themselves: &#34;It features a Martini-like API&#34;. It&#39;s MVC, idiomatic Golang usually isn&#39;t MVC.</p></pre>MrSaints: <pre><blockquote> <p>It&#39;s not much different than martini. It&#39;s just a one framework for everything. Sure it&#39;s much better than martini (a lot faster), but still, as they say themselves: &#34;It features a Martini-like API&#34;.</p> </blockquote> <p>So let me get this straight, you are basing your conclusion entirely on their description? Just a pure qualitative comparison?</p> <blockquote> <p>It&#39;s MVC, idiomatic Golang usually isn&#39;t MVC.</p> </blockquote> <p>You also seem pretty misguided to even think that it [Gin] is MVC. I&#39;m not sure where you got your definition of MVC from, but MVC is Model-View-Controller. It is an architectural pattern. A way of separating concerns / organising code. It is definitely achievable with Gin, but it is not an enforced pattern. You can sure as hell shove everything in a single handler. There is no <em>coding by convention</em> that you would normally see in other MVC frameworks, e.g. Revel, and Beego (or Laravel in PHP). But the beauty of it is that you can do it, if you want to...</p> <p>With regards to &#34;idiomatic Golang&#34;, I&#39;m not exactly sure I know what you mean. The fact that Gin handles each request in a separate Go routine, and <em>avoid</em> any sort of memory allocation should already be indicative of it being &#34;idiomatic&#34; (heck, it even takes advantage of defers, and recovery through its &#34;crash-free&#34; / recovery middleware). It is also well-documented with good test coverage. Errors are propagated through return values, and it employs interfaces pretty heavily. Obviously, it&#39;s not 100% perfect, pure idiomatic Go code, but neither are most Go projects (even those under the official Go repository).</p> <p>Sorry, I just find it annoying how there&#39;s almost an immediate knee-jerk reaction against using any sort of &#34;framework&#34;. I know you recommended using a &#34;http router (like gorilla mux)&#34;, and &#34;middleware like negroni&#34;, but what you are essentially doing by combining the two of them is doing what Gin is doing. </p></pre>cube2222: <pre><p>Ok then, it was also based on my short experience with it a while ago and what I&#39;ve been hearing around me. I still think he should try it without using a big framework like gin, but if he wants to, then it&#39;s probably the best (most idiomatic) to use.</p></pre>ianwalter: <pre><p>1) Yes. 2) The standard library is enough, but I&#39;m really liking <a href="https://github.com/celrenheit/lion" rel="nofollow">Lion</a>. It combines a fast router with a middleware system thats a bit easier to read and use than stdlib.</p></pre>karnd01: <pre><p>No framework at all, that&#39;s why I wrote <a href="https://github.com/go-playground/lars" rel="nofollow">https://github.com/go-playground/lars</a> you can register your own custom Context, register custom handler types (if needed) , handles STD middleware + a bunch of other patterns by default, built in way to avoid type casting your custom Context in your handlers.</p> <p>Add your own methods to your Context as you need them/as your app grows. No more getting painted into a corner by a framework!</p></pre>octoberxp: <pre><p>Go is pretty awesome for web apps, as many people here have said - you don&#39;t NEED a framework, but there are several to choose from should you want to try one. I&#39;ve been finding it an interesting project to develop my own &#34;micro-framework&#34; toolkit based around how I like to work. It&#39;s a good way to learn your way around the language and the libraries.</p></pre>CaptaincCodeman: <pre><p>While the Go standard library is great, I think some people are overstating that it&#39;s the only thing you need (but it&#39;s worth starting with and learning &#39;cause most other things build on it).</p> <p>A good framework isn&#39;t massive but will have convenient features to speed things up and handle things like parameters in routes, passing data through middleware (and hooking middleware in), rendering JSON, HTML etc... and other things.</p> <p>Can you write them all yourself? Yes. Should you? Wouldn&#39;t you rather write your app, not a framework?</p> <p>When I started I evaluated lots of frameworks or pieces that could be put together. The ones I liked best that I can recommend are:</p> <p>Echo Gin Goji</p> <p>All have, I think, borrowed good ideas from each other and as time goes on there is less between them. All have great performance and features and strong community around them.</p></pre>binaryblade: <pre><p>yes and none</p></pre>hockeyhippie: <pre><p>The standard libraries are fine, but I&#39;ve used this in a few projects lately and really like it: <a href="https://github.com/ant0ine/go-json-rest" rel="nofollow">https://github.com/ant0ine/go-json-rest</a></p></pre>dominotw: <pre><p>nah use nodejs much better suited for webapps.</p></pre>watr: <pre><p>Node.j&#39;s for sure, and then rewrite everything in golang once you get sick of callback hell. Seems to be the common theme of where and how Golan gets a lot of its new adopters.</p></pre>dominotw: <pre><blockquote> <p>Node.j&#39;s for sure, and then rewrite everything in golang once you get sick of callback hell. </p> </blockquote> <p>Not true. there is <code>async</code> promises ect.</p></pre>gogogogophers: <pre><p><a href="https://revel.github.io/" rel="nofollow">https://revel.github.io/</a></p></pre>robvdl: <pre><p>Please no, anything but Revel, I hear so many Go developers making this same mistake of making this their first framework, myself included, then they move on to Martini next, another mistake.</p> <p>Revel is weird, it doesn&#39;t use the normal Go build process, it puts routes in a text file which I don&#39;t like one bit.</p> <p>Either use stdlib as so many here have already suggested, or Negroni, or Gin, or Echo or Gocraft web is somewhat interesting too.</p> <p>But try to avoid Revel and Martini.</p></pre>rafael-py: <pre><p>Do you have sources for examples with negroni/gin/stdlib? I only had experiences with revel, and it wasn&#39;t bad, albeit, they were very small apps.</p></pre>

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

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