Handling request scoped dependencies in Golang without abusing the context

I’ve been programing for over 20 years in varying professional roles at this point, and there are a few things I’ve learned along the way that helps me keep things straight, especially when working with other developers, or in code bases where I tend to come back after a while away to pick it back up again. I’m a firm believer that when you write code, you should make everything as obvious as possible. This means no magic global variables, clever tricks, or hidden dependencies. I also think that you should rely on the compiler rather than tests to verify as much as possible, so in a strictly typed language like GoLang you would not rely on passing dependencies through as non-typed to be cast to the correct type further down the callstack. It often leads to runtime errors, and can make testing a lot more difficult than you would like as you need to know all the hidden dependencies. ...

July 20, 2025 · 6 min · Thomas Winsnes

Typesafe SQL queries in Golang

When writing web applications we often reach to ORMs to help us with the connection to the database layer. This is something that generally speed up the development of applications, but has a tradeoff in performance and complexity. I have worked in some very large code bases that took an expensive performance hit from the ORM. Some of the queries that were generated where interesting. Writing SQL directly is usually going to have better performance characteristics than auto-generating SQL queries based on a model. Especially as the complexity of the data grows. There are downsides with this, having to write loading and saving logic being a big time cost. It’s also important to write tests to ensure that there is no regression if there are changes in the data model. ...

February 12, 2025 · 2 min · Thomas Winsnes