top | item 15853308

Ask HN: What is your Golang web-dev tech stack?

98 points| aalhour | 8 years ago

I picked up Golang recently and I am curious about how people use it to develop web applications. How does your tech stack look like?

46 comments

order
[+] mdasen|8 years ago|reply
I've started using Echo[1] and it seems to provide most of what I'm looking for (routing, context, sessions, CSRF protection, form/json binding, etc). For templating, I'm using QuickTemplate[2] which creates statically generated templates, but Pongo2[3] and Jet[4] also look reasonable. sqlx[5], gorm[6], and sqlboiler[7] all seem reasonable for database access, depending on what your style is (sqlx being oriented toward manual statements, gorm being reflection-based orm-ish, and sqlboiler using go generate's code generation to make statically generated access for you).

If you don't want to piece things together yourself (and want a more Rails-like experience), Buffalo[8] is probably your best bet.

[1] https://echo.labstack.com/

[2] https://github.com/valyala/quicktemplate

[3] https://github.com/flosch/pongo2

[4] https://github.com/CloudyKit/jet

[5] https://github.com/jmoiron/sqlx

[6] https://github.com/jinzhu/gorm

[7] https://github.com/volatiletech/sqlboiler

[8] https://github.com/gobuffalo/buffalo

[+] aalhour|8 years ago|reply
Sweet! Buffalo looks really interesting. I was playing with Sails the other day, which is a Rails-like framework for nodejs, I will try Buffalo and try to compare the experience. Would you recommend Buffalo for a JSON Web API mobile backend project or would it be an overkill?
[+] tptacek|8 years ago|reply
Is there a way to use Echo where you're not using their weird handler interface, but rather just standard net/http Handlers?
[+] tptacek|8 years ago|reply
Even though I know they're well-designed, I find Go's web templates hard to work in. So I avoid them.

My stack is basically:

- Postgres, using pq and sqlx

- A codegen ORM I wrote that scrapes schemas and generates CRUD and lookup functions for all my database types. I don't think dynamic ORMs like gorm are the way to go for Go.

- A session library I wrote a year ago, and simple Go wrapper handlers to require sessions, enforce authentication, &c, passing things like "current user" and "current session" down to standard net/http Handlers through Context.

- 10-or-so JSON utility functions I take with me from project to project.

- React, via create-react-app, so I all my templating is done in JSX.

- net/http/httptest for testing.

[+] aalhour|8 years ago|reply
Any chance you have that ORM of yours open-sourced somewhere?
[+] avitzurel|8 years ago|reply
My 2 cents

At Globality[1], we use microcosm [2], an internally built framework for crafting applications. We have 45+ microservices, all built on top of it, and it's a joy.

I was looking for a framework that will give me similar benefits with Golang. Something that I can take out of the box with some convention-over-configuration.

I found micro [3] and gizmo [4]. (There are more)

It seems to me that a full-blown web app doesn't come very natural to Golang yet. There isn't a framework that will give you what you are used for from other languages/frameworks.

I have a lot of experience with Golang and built many tools, and it always felt more natural to me when there is no database/models involved.

[1] https://www.globality.com/en-us/

[2] https://github.com/globality-corp/?utf8=%E2%9C%93&q=microcos...

[3] https://github.com/micro/go-micro

[4] https://github.com/NYTimes/gizmo

[+] nerdywordy|8 years ago|reply
Gophers tend to roll their own and forego larger frameworks.

Piecing together libraries can absolutely be daunting, but once you get a starter app built your productivity will go way, way up.

I'd really recommend this (paid) course at https://www.usegolang.com

It walks you through pulling in different libraries (Gorilla Mux, GORM, etc), gluing them together, and structuring your code in a maintainable way.

A couple of other folks have mentioned Buffalo. It's a great ecosystem for building applications quickly, but I would strongly urge you to go through gluing the packages together yourself first to really understand what is going on underneath the magic.

[+] aalhour|8 years ago|reply
Solid advice. I will take a look at the course, looks interesting. Thanks for sharing.
[+] matthiase|8 years ago|reply
For APIs, I've used net/http and httprouter with great success. I've recently discovered Buffalo (https://github.com/gobuffalo/buffalo) which looks great for full-stack development but I have not used it for a production app.
[+] indescions_2017|8 years ago|reply
Also check out Træfik. A fast reverse proxy. With support for kubernetes, prometheus, let's encrypt, grpc, websockets and more. It may change the way you design your web backend ;)

https://traefik.io/

Am also looking forward to trying the new GoLand IDE from the JetBrains team. Currently using Atom but would be interested in dedicated integrations with gcloud sdk.

https://www.jetbrains.com/go/

[+] marcrosoft|8 years ago|reply
Go with sqlite DB using net/http, httprouter, and gorm. The goal is maintainability and easy deployment over scalability.
[+] didip|8 years ago|reply
* Standard library for a lot of things.

* https://github.com/go-chi/chi is pretty good. I have a need for a lot of custom middlewares, so I need something more fleshed out than net/http.

* All config files are written in TOML: https://github.com/BurntSushi/toml

* https://github.com/gocql/gocql for all Cassandra needs.

* Development work is done in Docker so everyone has a consistent env.

That's all, I tend to dislike overarching frameworks. Smaller libraries work better for me.

[+] aalhour|8 years ago|reply
Just took a look at Chi's RESTful API example, I like it. I also like the benchmarks. Judging by most of the comments on this thread, it looks like the community favors modular small tools over big fat frameworks, is that true?
[+] t3h2mas|8 years ago|reply
Gin/React. I was using templates but decided to offload some display logic on the frontend instead of creating more API endpoints. So I switched to React. I dig writing decoupled front/backends
[+] acangiano|8 years ago|reply
If you are creating an SPA application and you just need an API in Go, the standard library or one of the microframeworks like Gin work fine. If you are doing full-stack development, you'll be more productive with a framework even though the Go community tends to shy away from large frameworks. If I were to use Go for a web app today, I'd use Buffalo which is relatively Rails-like while still being very modular: https://gobuffalo.io/
[+] Bjorkbat|8 years ago|reply
I use it as a RESTful API for a single page app. I use some extra packages beyond those that come standard, but they don't really have a huge day-to-day impact on the code that I write.

Gorilla will probably make your life easier. I rely on the mux package quite a bit for routing purposes.

I also use Google's jsonapi package to maintain a semblance of orderliness when it comes to request and response data, but I wouldn't be hurting too much without it.

[+] cyrusaf|8 years ago|reply
HTTP: - gRPC for microservices - graphql for combining microservices for the frontend

DB: - dynamodb/psql depending on features. aws-sdk or base go sql package. - redis for caching. go-redis package.

Stats/logging: - statsd/graphite/grafana - sirupsen/logrus for logging

I usually write a wrapper for packages that will automatically report stats + logging.

[+] BlackjackCF|8 years ago|reply
I've used Echo in the past along with sqlx and Gorm.

I've found myself enjoying rolling/being more explicit about what it is that I need, so I now build out small web APIs just using a combination of Gorilla Mux + net/http.

[+] bjw181|8 years ago|reply
I'm curious. I've used GoLang's simple web server before, but I'm interested in what GoLang provides over Node. To me, it seems Go is especially well suited for microservices and tasks requiring a lot of CPU intensive processes while Node is better when working with small requests over the wire.

In other words, what is Go's main selling point in competing with Node in terms of its http server, TCP sockets, etc...

Can Go's awesome concurrency patterns be used to optimize server requests? Can it be well utilized as a proxy?

[+] weitzj|8 years ago|reply
gRPC, gRPC-Gateway, pgx, memcached, gorilla secure cookie, gorilla CSRF, gRPC-opentracing with Google Stackdriver integration, Uber-zap logging
[+] aalhour|8 years ago|reply
Interesting. What do you use gRPC for?