6 ms·
Ask HN: What Go framework for web API are you using in production?
- taneltanel 9y agoUsing no frameworks at all, only https://github.com/julienschmidt/httprouter https://github.com/julienschmidt/httprouter for routing.
- taneltanel 9y agoAnd https://github.com/gorilla/sessions https://github.com/gorilla/sessions for sessions.
- deleted 9y ago[deleted]
- Gonzih 9y agoYeah, I had really good experience with httprouter also. Everything in production is based on it.
- bauerd 9y agoHow do you handle database schema migrations?
- grey-area 9y agoI use SQL migrations for this, works fine. Only migrate up, never down, and store the name of migrations already run in the db.
- binarray2000 9y agoCould you please clarify. Which one of these do you mean (first three results when googling SQL migrations): (1) https://www.npmjs.com/package/sql-migrations https://www.npmjs.com/package/sql-migrations (2) https://flywaydb.org/documentation/migration/sql https://flywaydb.org/documentation/migration/sql (3) https://github.com/rubenv/sql-migrate https://github.com/rubenv/sql-migrate
- grey-area 9y agoNone of the above, sorry I didn't mean a tool called 'sql migrations' I meant I simply use sql files (rather than having a special language or config file that translates to sql which is another common approach). I use something I wrote myself (see link in other comment). Nothing fancy and could be replicated easily - save sql files for migrations, run migration if not in db already, then store in the db the name of the migration run.
- jzelinskie 9y agoThe best generic tool/library for migrations that I've found is https://github.com/remind101/migrate https://github.com/remind101/migrate We're using it in production on a few CoreOS projects.
- aczerepinski 9y agoMigrations are a minor pain point for me. The libraries I've used don't support running (all) pending migrations; only those with a timestamp more recent than the previous one. This means we have to finesse the timestamps manually as migrations get merged into the main branch and deployed to various environments. As such, the value offered by the migration library is pretty minimal compared to just remembering to pipe a .sql file directly into the database. Hopefully there's a more robust option out there that I just haven't found yet.
- grey-area 9y agoI take the approach of storing the name of any migrations run in the database in a metadata table - this means you can run them out of order, restore from a backup then run migrations not yet run etc. to test or adjust them. With multiple devs it's often the case that we want to run things out of order on production too, so ordering by time doesn't work and running manually is error-prone. Code for this here - it'd be pretty simple to put it in its own little tool or even a bash script or something, and there are surely some other tools that do something similar... This one psql only as it relies on the psql binary to load the sql, but hopefully gives you the idea. I haven't bothered developing it further to do things like run a single migration or down migrations as haven't required that so far. https://github.com/fragmenta/fragmenta/blob/master/migrate.go https://github.com/fragmenta/fragmenta/blob/master/migrate.g...
- NateDad 9y agowe use https://github.com/jackc/tern https://github.com/jackc/tern for migrations. It's pretty nice.
- camus2 9y agohttps://godoc.org/github.com/rubenv/sql-migrate https://godoc.org/github.com/rubenv/sql-migrate
- l-p 9y agoI toyed with this: https://github.com/mattes/migrate https://github.com/mattes/migrate Quite simple, does the job.
- tptacek 9y agoI use Rails migrations, via the standalone_migrations gem, and code-generate the basic CRUD Go stuff from the schema. I've tried a bunch of other migration tools but I don't think anyone has done a better job of it than Rails has.
- bauerd 9y agoCool, because this is actually what I ended up with myself in a dummy Go setup of mine (after having reinvented AR's migrations poorly with a Bash script). I'm not really accustomed to Go's ecosystem yet, so: >and code-generate the basic CRUD Go stuff from the schema I guess you read schema.rb and output some structs and methods? Because a quick Google search only yielded some Yeoman plugins …
- tptacek 9y agoNo, I use Postgres and just query information_schema, and use the row/column information to populate text/template Go templates. There's a bunch of tools that do this already (one I know works is "xo"), but I wanted join-table support.
- adibalcan 9y agoI use Django OR and it has migrations system included
- johnnycarcin 9y agoYes, this. One of the things I love about go is the stdlib capabilities. I try to avoid a lot of frameworks as there seems to be too much "magic" going on that you end up having to figure out when it comes time to troubleshoot. The HttpRouter is bare bones enough to understand and build on top of while still adding some value and helping avoid creating boilerplate code on your own.
- jstewartmobile 9y agohttps://github.com/gin-gonic/gin https://github.com/gin-gonic/gin
- wjh_ 9y agoAlso using Gin, works really well.
- NateDad 9y agoWe use gin. It's mostly fine. If I were starting a new application, I'd probably use stdlib by itself.
- bbrks 9y agoMy old place uses Gin. Works well enough, but had some problems with URL param handling causing our API design to eventually become a mess.
- saiongole 9y agohttps://github.com/gorilla/mux https://github.com/gorilla/mux
- bitexploder 9y agohttps://github.com/bitexploder/gowebexample https://github.com/bitexploder/gowebexample I put together a little example web app based based on a few popular packages, including gorilla / mux. It's not a framework, just a nice starting point for little apps.
- psynapse 9y agoSame here. I love this about Go. A router and you are off and running. It is so simple to wrap handlers with your own middleware for auth, pre-flighting etc.
- cristaloleg 9y agohttps://github.com/go-chi/chi https://github.com/go-chi/chi
- philip1209 9y agoWe run grpc-web with a big single-page VueJS app on the frontend. That way, Go is just the Api server, and the frontend handles all the routing and stuff.
- Dlotan 9y agoWe will also try to go this path. What is your overall satisfaction with this approach? I saw that grpc-web is marked as alpha and the grpc team itself wants to implement something which is kind of comparable.
- philip1209 9y agoIt's been good. I need to figure out SSR, either in Go or though a Node microservice. I really like how a proto file defines our whole Api. It makes designing and referencing the Api easy.
- binocarlos 9y agoThis seems to be a popular answer - i.e. go is the web framework.
- misframer 9y agohttps://github.com/VividCortex/siesta https://github.com/VividCortex/siesta
- erazor42 9y agohttps://echo.labstack.com/ https://echo.labstack.com/
- prettynatty 9y agogrpc-go (https://github.com/grpc/grpc-go https://github.com/grpc/grpc-go) + grpc-gateway (https://github.com/grpc-ecosystem/grpc-gateway https://github.com/grpc-ecosystem/grpc-gateway)
- krullie 9y agoSame here. I was sceptical about code generation and the whole protobuf as a base thing but i'm really liking it. Especially when you throw opentracing in the mix.
- samblr 9y agoCan anybody share experience with gobuffalo. https://gobuffalo.io/ https://gobuffalo.io/
- Queue29 9y agonet/http with gorilla/mux for routing
- richardknop 9y agoSame here. I never really liked idea of frameworks like Spring/Django for Golang. Rather build very small services and mostly use just standard library, perhaps some simple packages for specific tasks.
- richardknop 9y agoJust standard library (net/http), no framework. Specific packages for specific tasks if needed (sqlx for database etc).
- hiepph 9y agoJust a router is enough for me https://github.com/buaazp/fasthttprouter https://github.com/buaazp/fasthttprouter
- tmaly 9y agoI am using Gin for my food side project https://bestfoodnearme.com https://bestfoodnearme.com at my day job in fintech I use the standard library and gorilla/mux
- dblooman 9y agohttps://github.com/ant0ine/go-json-rest https://github.com/ant0ine/go-json-rest
- garfij 9y agoWe use this too. It's not bad if all you're ever doing is returning json, but escaping from their `rest.ResponseWriter` to a normal `http.ResponseWriter` is always sad when you need to write out anything else. That's a pretty good summary of the rest of it for me too...pretty good, but sad that it doesn't adhere to the standard libs `http` interfaces
- barrongineer 9y agoWe've been pretty happy with https://gobuffalo.io https://gobuffalo.io so far. We're serving up a Vue.js app with it. We needed a single binary to deploy on a client's server with no external dependencies and buffalo fits the bill. It comes with a cli that runs webpack and does hot reloads on save. It also has a build command that will bundle all the assets up to shove in the binary.
- nicpottier 9y agoChi gives us just enough while still adhering to all the Golang standards: https://github.com/go-chi/chi https://github.com/go-chi/chi Do augment it a bit here and there with other libraries.
- wvh 9y agoI've been using the standard library, httptreemux and Chi, depending on how large the project is. I have also used Gorilla in the past, and sometimes use Alice to compose handlers. I prefer to stay close to the standard library, so as to not get stuck with code that depends too heavily on a third library with no easy way to entangle that dependency. I've still got nightmares from late '90s PHP and early 2000 Zope framework disasters... not with a 10 foot pole. Though when your application gets bigger, it makes sense to pull in a good library for some route grouping and helper functions – there are so many options, it's not worth your while to roll your own. And unless you have very specific requirements, the performance is probably not a relevant concern in a real application either.
- crehn 9y agohttps://github.com/valyala/fasthttp https://github.com/valyala/fasthttp Crazy fast and has worked fine under heavy load.
- nonane 9y agohttps://github.com/labstack/echo https://github.com/labstack/echo For building a REST API
- petepete 9y agoI'm using Negroni middleware and Vestigo for routing. Both are simple, fast and elegant, and are being actively developed. [0] https://github.com/urfave/negroni https://github.com/urfave/negroni [1] https://github.com/husobee/vestigo https://github.com/husobee/vestigo
- telefonica 9y agohttps://github.com/goadesign/goa https://github.com/goadesign/goa
- ollieco 9y agoNot a full blown framework, but Chi works pretty well - https://github.com/go-chi/chi https://github.com/go-chi/chi
- GeertJohan 9y agoI am using Chi in several projects running in large production environments.
- subsidd 9y agoWhat has been your experience with gin? How do you use it in your application?
- nilslice 9y agohttps://ponzu-cms.org https://ponzu-cms.org for back end & https://github.com/gorilla/mux https://github.com/gorilla/mux if needs a Go front end.
- programd 9y agoThe Go standard library has most of what you need for basic API servers. However as has been stated here, some things are not worth spending time crafting yourself. Also for modern Docker/Kubernetes ops environments you need some additional infrastructure for table stakes. Here's my standard Nulladmin.com stack: Routing - https://github.com/go-chi/chi https://github.com/go-chi/chi Command flags - https://github.com/spf13/pflag https://github.com/spf13/pflag Config - https://github.com/spf13/viper https://github.com/spf13/viper Logging - https://github.com/Sirupsen/logrus https://github.com/Sirupsen/logrus Metrics - https://github.com/prometheus/client_golang/prometheus https://github.com/prometheus/client_golang/prometheus SQL helper - https://github.com/jmoiron/sqlx https://github.com/jmoiron/sqlx OpenTracing - https://github.com/opentracing/opentracing-go https://github.com/opentracing/opentracing-go
- zacharynewton 9y agoGin for most parts Zap for logging Then Docker up the binary in busybox and run on AWS ECS I've tinkered with echo and a couple other frameworks, but Gin is widely used enough that I can usually stack overflow most issues.
- gnahckire 9y agoCurrently using gokit: https://github.com/go-kit/kit https://github.com/go-kit/kit Really nice interface for adding tracing, middleware/finalizer logging/metrics, circuit-breakers, etc to your application.
- prettynatty 9y agoBut sadly no streaming yet
- chimen 9y agoI use beego.me for https://typely.com https://typely.com and It's great so far. It has a lot of features but I use just a few which worked great from day 1.
- ddw 9y agonet/http and Gorilla Mux
- codehack 9y agoI wrote my own lightweight framework - https://github.com/codehack/go-relax https://github.com/codehack/go-relax
- dash1291 9y agoAt Grofers, we built a framework using Swagger that we use for building aggregated APIs and also open-sourced it couple of days back. It can be found here - https://github.com/grofers/go-codon https://github.com/grofers/go-codon
- agnivade 9y agoNo framework as such. Just some tools from here and there - gorilla/mux + negroni + net/http.
- willygold 9y agohttprouter is all I need