3 ms·
I mean, net/http does it. That's the standard library. A go convention that I've made up, or that is perhaps a real one, is to always look at the standard lib
by jrockway 4y ago
I mean, net/http does it. That's the standard library.
A go convention that I've made up, or that is perhaps a real one, is to always look at the standard library for guidance on how to write Go. net/http suffers a little bit from being a very early library and thus you might not want to emulate its API surface. But in general, the Go team thought "you know what every HTTP handler in Go needs? recovery from panics" and that is worth some weight when considering your own design.
I would personally recommend fuzz testing your code, including HTTP handlers. The more panics you find in development, the fewer customers you lose from panics in production. Remember that recovering from a panic in an HTTP handler still means your user's request didn't get processed. They are not happy about that, even if your program can still service other users.
- deleted 4y ago[deleted]