<p>Hi, I want to check out golang for making web apps. What are the cool cats using to develop web apps in 2017? </p>
<p>Thanks.</p>
<hr/>**评论:**<br/><br/>icholy: <pre><p>Just use the standard library. Grab a 3rd party router if you need it.</p></pre>H1Supreme: <pre><p>Maybe something to handle user auth too. But, overall a router and Go's standard library is all I've ever needed.</p></pre>emansom: <pre><p>net/http</p></pre>m3wm3wm3wm: <pre><p>I love it how this sub gets this same question on a weekly basis.</p></pre>edgardcastro: <pre><p>I'm enjoying using <a href="https://echo.labstack.com/" rel="nofollow">echo</a> as a micro web framework <em>a lot</em>.</p>
<p>Also, <a href="http://jinzhu.me/gorm/" rel="nofollow">gorm</a> for your orm needs.</p></pre>dlsniper: <pre><p>Or sqlx </p></pre>eaglex: <pre><p><a href="https://gowebexamples.github.io/" rel="nofollow">https://gowebexamples.github.io/</a></p></pre>pkieltyka: <pre><p>My take:</p>
<p>router: <a href="https://github.com/pressly/chi" rel="nofollow">https://github.com/pressly/chi</a></p>
<p>database querying and struct mapper: <a href="https://github.com/upper/db" rel="nofollow">https://github.com/upper/db</a></p></pre>iends: <pre><p>I've never seen upper before, it looks nice. However, none of the examples or documentation talks about joins. Is the only option to use the query builder?</p></pre>Zamicol: <pre><p>See the Awesome list:</p>
<p><a href="https://github.com/avelino/awesome-go#web-frameworks" rel="nofollow">https://github.com/avelino/awesome-go#web-frameworks</a></p></pre>fancy_pantser: <pre><p>Basics: <a href="https://golang.org/doc/articles/wiki/" rel="nofollow">https://golang.org/doc/articles/wiki/</a></p>
<p>Popular router/dispatcher: <a href="https://github.com/gorilla/mux" rel="nofollow">https://github.com/gorilla/mux</a> </p>
<p>Get you some middleware handling -- Negroni is popular: <a href="https://github.com/urfave/negroni" rel="nofollow">https://github.com/urfave/negroni</a></p>
<p>Datastores: choose your own adventure! There are many. For RDBMSes at a slightly higher level, try <a href="http://jinzhu.me/gorm/" rel="nofollow">GORM</a> or <a href="http://jmoiron.github.io/sqlx/" rel="nofollow">sqlx</a>.</p></pre>robvdl: <pre><p>I wouldn't really recommend GORM anymore:</p>
<ul>
<li>Automigrate is so basic that it won't even put constraints on foreign keys (unless that has been fixed since, you just end up with simple integer fields without constraints on them)</li>
<li>Embedding *gorm.Model is weird, it adds columns like deleted_at and encourages soft deletes, leaving the record behind and marking it as deleted instead.</li>
<li>I have read multiple times now on Reddit golang that the code base is pretty bad and in dire need of fixing up, all while better alternatives have popped up.</li>
</ul>
<p>See: <a href="https://www.reddit.com/r/golang/comments/5pgma4/my_quest_to_improve_gorm_the_object_relational/" rel="nofollow">https://www.reddit.com/r/golang/comments/5pgma4/my_quest_to_improve_gorm_the_object_relational/</a></p>
<p>Also sqlx is low-level, not high-level, it encourages you to write SQL by hand which makes it low-level in my books.</p></pre>fancy_pantser: <pre><p>Why not "anymore"? These are not new features.</p>
<p>Embedding is how golang handles data structure inheritance; it would be weird to do it another way. In many basic CRUD applications, soft-deletion is what you want for many tables so they built it in. <a href="https://github.com/jinzhu/gorm/issues/1163" rel="nofollow">You don't have to embed gorm.Model in your structs or use soft delete</a> (aka tombstones). You can add/remove/modify your model structs at will to use all/some/none of the "batteries included" GORM features.</p>
<p>Personally I like working from the DB -> code and not the other way around when it comes to Go, so <a href="https://github.com/vattle/sqlboiler" rel="nofollow">SQLBoiler</a> is my jam. It's also much faster in benchmarks. I didn't recommend it above, however, because OP is new to writing webapps in Go and asked what's popular (and, I assume, they'll find lots of support material for).</p>
<p>Finally, I'm glad that we agree that sqlx is slightly higher than low-level. I recommend it here because it's widely used and lets anyone already comfortable with SQL just get the job done at the query level without the nitty-gritty of manual marshaling.</p></pre>robvdl: <pre><p>The only reason I mentioned "anymore" is because I used to use it a LONG time ago, before I even came across sqlx and sqlboiler, when there weren't all that many choices, e.g. it was GORM or GORP or stdlib. I thought it was an OK library at first, but it wasn't until later I realised that the auto creation of tables from models didn't even create foreign keys properly, as in they were lacking the constraints on them which made the auto create feature kind of useless. The soft deletes were also kind of a "surprise" to me at first, but I do realise you don't have to have the deleted_at field either... it was just an odd surprise to me at the time.</p>
<p>With soft deletions you constantly have to be aware of "deleted" records in your querying, what if you join to something that is "soft deleted" for example, you can get your data in an inconsistent state that way too.</p></pre>fancy_pantser: <pre><p>There still aren't many "complete" ORMs to choose from and they all have some big tradeoffs. I'm still not completely satisfied with anything I've tried, but I do check out new ones when they get past the "pet project" stage.</p>
<p>What would you look for in an ideal Go ORM? Is it just "a Rails/Django/Hibernate/... clone" or something that takes specific advantage of the language and common patterns?</p></pre>robvdl: <pre><p>I'm not really sure now what I would want out of a Go ORM, I have spent quite a few years with Django, and in the last year I have done a lot of very complex SQLAlchemy querying using the ORM and SQLAlchemy query like language. I am kind of over ORM's I think after that project, SQLAlchemy is a complex beast to master but it taught me a lot more about just writing SQL by hand instead. So I was more thinking of avoiding ORMs all together in Go and just doing raw SQL instead.</p></pre>apxp: <pre><p>GoBuffalo</p></pre>hoffentlich: <pre><p>What an ugly pasta mix. </p></pre>sybrandy: <pre><p>I personally like httprouter. While it is supposed to be fast, I just really like it because I find it easier to create my rest endpoints when I declare them per method and per path vs. how the default net/http mux works. However, this is personal preference more than anything else.</p></pre>DustinHeroin: <pre><p>Anyone a fan of <a href="https://github.com/valyala/fasthttp" rel="nofollow">fasthttp</a>? Echo v2 used to support it. Not sure why other web frameworks haven't thought of taking advantage of it yet.</p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传