Live data from Hacker News

Go in Production – Lessons Learned

tdom.dev

11–20 of 109 posts

Re: Go in Production – Lessons Learned

#11
You almost certainly don't need a web framework. Over the long term, it's easy to find yourself boxed in with how opinionated many of them are.

Instead, if you build on the standard library, you can compose your application from there- a good muxer, some standard middleware that are generic http.Handler's, a session library, etc.

Re: Go in Production – Lessons Learned

#15
post #5

> silently handling panics That has a bad smell

Especially since caught panics amount to exceptions and most Golang code isn't exception safe. It's a recipe for leaking database connections, deadlocks, etc.

Go error handling is awful, but this isn't a fair.

In go, if you write code like the following:

    conn, err := db.Connect()
    defer conn.Close()
That defer will be run during a panic. Same thing as 'defer mutex.Unlock()'

Yes, like most of go, it's manual and painful and poorly thought out, but most people do follow these patterns, so for the most part go code will safely unwind from a panic.

Re: Go in Production – Lessons Learned

#16
post #8
post #6

Earlier quoted context omitted.

What path to this enlightenment would you recommend to one who has cut his teeth and delivered many projects (over many years) in Rails/Django?

This is a side effect of go’s lack of meta programming to be honest. So much magic that is possible in rails/django/etc is just not possible in golang. This leads to go web frameworks being sort of semi-hard mountainous turds of code generation. You’ll want to stick to stdlib after sifting through them and deciding they aren’t worth it.

After Django, writing database code manually in Go is not fun at all.

Re: Go in Production – Lessons Learned

#19
post #17

Why would you want to serve a 200 with an error message in a JSON response body?

I've seen this pattern before, and one can argue that it is the correct one. Your options are your http status are your application's status, which I think is what most of us are used to.

The other one is http status codes are http status codes. As in the http request was done correctly, but the application code wasn't. More specifically, http layer was executed successfully, but the application layer was not.

Re: Go in Production – Lessons Learned

#20
post #11

You almost certainly don't need a web framework. Over the long term, it's easy to find yourself boxed in with how opinionated many of them are. Instead, if you build on the standard library, you can compose your application from there- a good muxer, some standard middleware that are generic http.Handler's, a session library, etc.

So, you chose a good muxer. Now, which of hundreds of logging, cors, sessions, jwt and permissions middlewares work with said mud and with each other best?

Or, and bear with me here, you can outsource those decisions to other folks, and just write your business logic.

Post reply on HN