<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'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'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've used and I think that's about all you need.</p></pre>balloonanimalfarm: <pre><p>The core of Go is built around writing good web-apps, so it isn'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'll write a Wiki in about 90 lines of code.</p>
<p>There are a lot of middlewares that "just work" together because they follow Go'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's awesome in golang), a http router (like gorilla mux), and if you need to, but it'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't really idiomatic Go and aren't needed at all.</p></pre>MrSaints: <pre><p>I'm not too sure about Martini, but I definitely wouldn't count Gin as a "big framework". I'd like to know why you think that's the case, and why you don't consider it to be idiomatic Go.</p></pre>cube2222: <pre><p>It's not much different than martini. It's just a one framework for everything. Sure it's much better than martini (a lot faster), but still, as they say themselves: "It features a Martini-like API". It's MVC, idiomatic Golang usually isn't MVC.</p></pre>MrSaints: <pre><blockquote>
<p>It's not much different than martini. It's just a one framework for everything. Sure it's much better than martini (a lot faster), but still, as they say themselves: "It features a Martini-like API".</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's MVC, idiomatic Golang usually isn't MVC.</p>
</blockquote>
<p>You also seem pretty misguided to even think that it [Gin] is MVC. I'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 "idiomatic Golang", I'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 "idiomatic" (heck, it even takes advantage of defers, and recovery through its "crash-free" / 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'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's almost an immediate knee-jerk reaction against using any sort of "framework". I know you recommended using a "http router (like gorilla mux)", and "middleware like negroni", 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'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's probably the best (most idiomatic) to use.</p></pre>ianwalter: <pre><p>1) Yes. 2) The standard library is enough, but I'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'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't NEED a framework, but there are several to choose from should you want to try one. I've been finding it an interesting project to develop my own "micro-framework" toolkit based around how I like to work. It'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's the only thing you need (but it's worth starting with and learning 'cause most other things build on it).</p>
<p>A good framework isn'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'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'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'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'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't use the normal Go build process, it puts routes in a text file which I don'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't bad, albeit, they were very small apps.</p></pre>
Should i write my next webapp in golang? If so, which framework would you recommend?
xuanbao · · 1130 次点击这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传