Whats your REST API Stack?

blov · · 381 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>I&#39;m about to start a project where i&#39;m going to use Go for the rest api, i was wondering what libraries/frameworks are you using for http, routing or database.</p> <p>Thanks in advance!</p> <hr/>**评论:**<br/><br/>neoasterisk: <pre><blockquote> <p>i was wondering what libraries/frameworks are you using for http, routing or database.</p> </blockquote> <p>What I use for the above is <a href="https://golang.org/pkg/net/http/">this</a> and <a href="https://golang.org/pkg/database/sql/">that</a> in combination with the appropriate database driver. If you are using jwt you might also want to use <a href="https://github.com/dgrijalva/jwt-go">this</a> package.</p></pre>randomsofr: <pre><p>I&#39;ve been doing the same, but this new project is going to be big, and using plain database/sql is going to result in a huge codebase, i&#39;m considering a ORM or a library.</p></pre>neoasterisk: <pre><blockquote> <p>I&#39;ve been doing the same, but this new project is going to be big, and using plain database/sql is going to result in a huge codebase, i&#39;m considering a ORM or a library.</p> </blockquote> <p>If you are going down that road, the ones I&#39;ve heard the most buzz around are <a href="https://github.com/vattle/sqlboiler">https://github.com/vattle/sqlboiler</a> and <a href="https://github.com/jmoiron/sqlx">https://github.com/jmoiron/sqlx</a>.</p></pre>carsncode: <pre><p>I&#39;m using the standard library plus mgo for connectivity to Mongo. I was using httprouter but it honestly wasn&#39;t hard to write my own routing, and I get better performance and more flexibility rolling my own. It&#39;s just a handful of switch statements.</p></pre>randomsofr: <pre><p>Cool, how&#39;s Mongo working for you?</p></pre>carsncode: <pre><p>It&#39;s great for rapid prototyping, practically zero effort, but there can be some hurdles to overcome in production when you need scale and fault tolerance. I&#39;m planning on writing alternate database layers so it can be hooked up to postgres (or something postgres compatible like Cockroach).</p></pre>randomsofr: <pre><p>I&#39;ll stick with Postgres then, i was thinking on using Mongo at first, and then move to Postgres, but i think ill start with Postgres.</p> <p>Thanks!</p></pre>Terudax: <pre><p>I am using <a href="https://github.com/zebresel-com/mongodm" rel="nofollow">mongodm</a> in production. </p></pre>qu33ksilver: <pre><p>If you are <em>very</em> confident that your schema isn&#39;t going to change, starting off with postgres is cool. Otherwise, I will recommend start off with Mongo for a couple of months, let the schema settle down, and then switch to postgres. One quickly gets tired to doing &#39;ALTER TABLE&#39; commands, and adding default values to go around null constraints.</p> <p>Of course, if your DB related code is tied to the &#34;type&#34; of database, then its gonna be a problem. Starting with postgres is justified in that case.</p></pre>sairamk: <pre><p>What I have done was, used Mongo to prototype and moved on to MySQL once its stable. </p> <p>This was for an app couple of years ago. </p></pre>bear1728: <pre><p>Mostly <a href="https://golang.org/pkg/net/http/" rel="nofollow">https://golang.org/pkg/net/http/</a> but with the router from <a href="https://github.com/pressly/chi" rel="nofollow">https://github.com/pressly/chi</a> . Also used some very small custom utility wrappers for errors from handlers. The database is just <a href="https://golang.org/pkg/database/sql/" rel="nofollow">https://golang.org/pkg/database/sql/</a> with <a href="https://github.com/mattn/go-sqlite3" rel="nofollow">https://github.com/mattn/go-sqlite3</a> . Also a few custom utility wrappers for inserting several rows in a transaction and such. Authentication is stored in cookies with <a href="https://github.com/gorilla/securecookie" rel="nofollow">https://github.com/gorilla/securecookie</a> . We use Auth0 for authentication, but this doesn&#39;t require any dependencies. You just have to send some tokens and then make an http endpoint to authenticate. They have a library if you want to do fancier things though.</p> <p>Logs are printed to stdout. I&#39;ve been looking at <a href="https://github.com/agnivade/funnel" rel="nofollow">https://github.com/agnivade/funnel</a> as something to handle those. It&#39;s not a huge project so we don&#39;t need anything very fancy (hence sqlite).</p> <p>I made a dependency graph using <a href="https://github.com/hirokidaichi/goviz" rel="nofollow">https://github.com/hirokidaichi/goviz</a> at some point, but I don&#39;t know where it is right now.</p> <p>Edit: I meant to add I don&#39;t use an ORM or anything, just plain SQL. The only generated code for the database is the sql file, I use a tool I wrote <a href="https://github.com/tscholl2/embd" rel="nofollow">https://github.com/tscholl2/embd</a> which just takes a sql file and adds it as a string in a go file.</p></pre>itachi_amaterasu: <pre><p>Author of <a href="https://github.com/agnivade/funnel" rel="nofollow">https://github.com/agnivade/funnel</a> here. Thanks for taking a look at it !</p></pre>juicemia: <pre><p>net/http database/sql</p></pre>baseball2020: <pre><p>Go-kit and squirrel for sql. </p></pre>TheMue: <pre><p>Built my own to have a bit more comfort than the standard. It&#39;s <a href="https://github.com/tideland/gorest" rel="nofollow">https://github.com/tideland/gorest</a>. Here at work together with <a href="https://github.com/tideland/gocouch" rel="nofollow">https://github.com/tideland/gocouch</a> for persistency. </p></pre>arcagenis: <pre><ul> <li><a href="https://github.com/pressly/chi" rel="nofollow">Chi</a> for Routing</li> <li><a href="https://github.com/dgrijalva/jwt-go" rel="nofollow">jwt-go</a> </li> <li><a href="https://github.com/satori/go.uuid" rel="nofollow">satori/go.uuid</a></li> <li><a href="https://github.com/sirupsen/logrus" rel="nofollow">logrus</a> for logs</li> </ul></pre>codepushr: <pre><p>I&#39;ve built a multi-tenant SaaS api with multiple api versions, so as you can see it&#39;s not a small project. For that I&#39;m using the following stack:</p> <ul> <li>labstack/echo (route groups for e.g. api versions, lots of useful middleware)</li> <li>jinzhu/gorm (orm)</li> <li>mattes/migrate (migrations)</li> <li>testfixtures (test fixtures)</li> <li>urfave/cli (cli for migrations, fixtures or running the server)</li> <li>mikespook/gorbac (access control for tenants)</li> <li>go-playground/validator (model validation in handlers/controllers after binding)</li> <li>kelseyhightower/envconfig (for passing configs to the application, useful for deployment/docker)</li> </ul></pre>codepushr: <pre><p>Although i might switch my db layer to sqlx or go-pg.</p></pre>randomsofr: <pre><p>why?</p></pre>codepushr: <pre><p>GORM doesn&#39;t support deep scanning like for relations. for a simple belongs_to relation it fires a whole second SELECT statement instead of JOINing. the <code>preload</code> method is officially the best-practice for doing that - <a href="https://github.com/jinzhu/gorm/issues/441" rel="nofollow">https://github.com/jinzhu/gorm/issues/441</a></p></pre>randomsofr: <pre><p>wow, good to know, i think i&#39;m going to use sqlx then,</p></pre>UnknownTed: <pre><p><a href="https://www.reddit.com/r/golang/comments/4tt16b/is_this_a_reasonable_set_of_choices_for_web_dev/d5kbvjz/" rel="nofollow">https://www.reddit.com/r/golang/comments/4tt16b/is_this_a_reasonable_set_of_choices_for_web_dev/d5kbvjz/</a></p></pre>tscs37: <pre><p>gorilla/mux and silvertape to hold it together.</p> <p>api2go was probably the best stack I worked with, Ember makes that an instant REST api without any serious work.</p> <p>The rest (pun not intended), middlewares and such, is basically coded from scratch since it&#39;s usually not as bad.</p></pre>bruinboi: <pre><p>Using gin in production with a bunch of different middleware for throttling, cors, jwt auth, etc. </p> <p>seriously looking at chi - seems solid and the middleware you get &#34;in the box&#34; is pretty good. So far I like it. </p></pre>tvmaly: <pre><p>I also have been using Gin. I am curious how Gin achieved zero allocations while still using their own context verse Chi which is using the native context with 2 allocations.</p></pre>codepushr: <pre><p>What are you using for throttling?</p></pre>bruinboi: <pre><p>tollbooth for rate limiting and a very simple custom piece of code for connection limiting</p></pre>iris-go: <pre><ul> <li>http,routing -&gt; github.com/kataras/iris (production-ready, hot-reload, server (TLS), sessions &amp; flash messages, websockets, 6 optional template engines, rich routing including grouping, parameterized and (wild)subdomains(ex: api.mydomain.com), serve embedded static files, full restful methods, a tone of middleware, net/http stdlib compatible and more) </li> <li>database -&gt; github.com/jinzhu/gorm (orm)</li> <li>extra -&gt; github.com/go-playground/validator (form and model validation)</li> </ul> <p>These will give you a quick introduction to go&#39;s world. A Great Advantage over other developers, your app can be faster than your competitors and once you learn these you will be able to move forward and start distributing your app in many pieces and connect them via a load balancer /or/and proxy. Hope that helped you, have a nice day and first of all happy coding!</p></pre>

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

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