Advice for writing HTTP services in Go
Six years ago Mat posted a great article about writing HTTP services. Now we got an updated version and I really like some of the advice in there.
Encoding / decoding in one place makes your life a lot easier and reduces a good amount of code duplication. It is actually one of the use cases that make me appreciate the existence generics. Same goes for validating data.
I am not a big fan of deferring setup code. It makes it a lot easier for an endpoint to fail at a random time, the first time it is called. And it adds latency to the first one hitting the endpoint which I also think is not very nice. Generally starting an application is pretty quick. Even if a few places run expensive code. As startups are not happening frequently except in some serverless environments I would evaluate this very carefully before implementing.