Hacker News new | comments | show | ask | jobs | submit login
Ask HN: What Go framework for web API are you using in production?
110 points by srameshc 6 months ago | hide | past | web | favorite | 63 comments

Using no frameworks at all, only https://github.com/julienschmidt/httprouter for routing.

Yes, 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.

Yeah, I had really good experience with httprouter also. Everything in production is based on it.

How do you handle database schema migrations?

I 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.

Cool, 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 …

No, 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.

The best generic tool/library for migrations that I've found is https://github.com/remind101/migrate

We're using it in production on a few CoreOS projects.

Migrations 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.

I 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.


I toyed with this: https://github.com/mattes/migrate

Quite simple, does the job.

I use SQL migrations for this, works fine. Only migrate up, never down, and store the name of migrations already run in the db.

Could 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

(2) https://flywaydb.org/documentation/migration/sql

(3) https://github.com/rubenv/sql-migrate

None 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.

we use https://github.com/jackc/tern for migrations. It's pretty nice.

I use Django OR and it has migrations system included

We've been pretty happy with 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.

The 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

Command flags - https://github.com/spf13/pflag

Config - https://github.com/spf13/viper

Logging - https://github.com/Sirupsen/logrus

Metrics - https://github.com/prometheus/client_golang/prometheus

SQL helper - https://github.com/jmoiron/sqlx

OpenTracing - https://github.com/opentracing/opentracing-go

Same 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.


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.


For building a REST API

We use gin. It's mostly fine. If I were starting a new application, I'd probably use stdlib by itself.

My old place uses Gin. Works well enough, but had some problems with URL param handling causing our API design to eventually become a mess.

Also using Gin, works really well.

Just standard library (net/http), no framework. Specific packages for specific tasks if needed (sqlx for database etc).

I'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.

Same 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.

We 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.

We 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.

It'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.

This seems to be a popular answer - i.e. go is the web framework.

Currently using gokit: https://github.com/go-kit/kit

Really nice interface for adding tracing, middleware/finalizer logging/metrics, circuit-breakers, etc to your application.

But sadly no streaming yet

I am using Gin for my food side project https://bestfoodnearme.com

at my day job in fintech I use the standard library and gorilla/mux

I'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

[1] https://github.com/husobee/vestigo

At 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

Can anybody share experience with gobuffalo.


https://ponzu-cms.org for back end & https://github.com/gorilla/mux if needs a Go front end.

Chi gives us just enough while still adhering to all the Golang standards: https://github.com/go-chi/chi

Do augment it a bit here and there with other libraries.

net/http with gorilla/mux for routing

Same 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.

I use beego.me for 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.

I wrote my own lightweight framework - https://github.com/codehack/go-relax

Gin 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.

Not a full blown framework, but Chi works pretty well - https://github.com/go-chi/chi

I am using Chi in several projects running in large production environments.

Just a router is enough for me https://github.com/buaazp/fasthttprouter


Crazy fast and has worked fine under heavy load.

We 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

No framework as such. Just some tools from here and there - gorilla/mux + negroni + net/http.

What has been your experience with gin? How do you use it in your application?

httprouter is all I need

net/http and Gorilla Mux

Applications are open for YC Summer 2018

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact