How I use HTMX with Go
When I want to add sprinkles of interactivity to a web application, I'm a big fan of using HTMX. I like that it makes it easy to give interactions a smooth app-like feel, I like that it minimizes the...
View ArticleGo Experiments Explained
Go often ships with experimental features as part of a release. These experimental features can take different forms: sometimes they're completely new packages in the standard library, sometimes...
View ArticleGo Naming Conventions: A Practical Guide
Choosing the right names in your codebase is an important (and sometimes difficult!) part of programming in Go. It's a small thing that makes a big difference — good names make your code clearer, more...
View ArticleA modern approach to preventing CSRF in Go
Go 1.25 introduced a new http.CrossOriginProtection middleware to the standard library — and it got me wondering: Have we finally reached the point where CSRF attacks can be prevented without relying...
View ArticleThe 9 Go test assertions I use (and why)
A few weeks ago Anton Zhiyanov published the blog post Expressive tests without testify/assert. It's a good and well thought-out post, and I recommend giving it a read if you haven't already. In the...
View ArticleHow to manage configuration settings in Go web applications
When I'm building a web application in Go, I prefer to use command-line flags to pass configuration settings to the application at runtime. But sometimes, the client I'm working with wants to use...
View ArticleOrganize your Go middleware without dependencies
For many years, I've used third-party packages to help organize and manage middleware in my Go web applications. In small projects, I often used alice to create middleware 'chains' that I could reuse...
View ArticleWhen is it OK to panic in Go?
If you've been working with Go for a while, you might be familiar with the Go proverb "don't panic". It's a pithy way of saying: "handle errors gracefully, or return them to the caller to handle...
View ArticleHow to manage tool dependencies in Go 1.24+
One of my favourite features of Go 1.24 is the new functionality for managing developer tooling dependencies. By this, I mean tooling that you use to assist with development, testing, build, or...
View Article11 tips for structuring your Go projects
When working with Go, you have three main building blocks to help organize your code: files, packages and modules. But as Go developers, one of the common challenges we have is knowing how to best...
View ArticleQuick tip: Implementing an in-memory cache in Go
In almost all web applications that I build, I end up needing to persist some data – either for a short period of time (such as caching the result of an expensive database query), or for the lifetime...
View ArticleDemystifying function parameters in Go
In this post we're going to talk about how (and why!) different types of function parameters behave differently in Go. If you're new (or even not-so-new) to Go, this can be a common source of...
View ArticleQuick tip: A time-saving Makefile for your Go projects
Whenever I start a new Go project, one of the first things I do is create a Makefile in the root of my project directory. This Makefile serves two purposes. The first is to automate common admin tasks...
View ArticleHow to use the http.ResponseController type
One of my favorite things about the recent Go 1.20 release is the new http.ResponseController type, which brings with it three nice benefits: You can now override your server-wide read and write...
View ArticleAn Introduction to Packages, Imports and Modules in Go
This tutorial is written for anyone who is new to Go. In it we'll explain what packages, import statements and modules are in Go, how they work and relate to each other and — hopefully — clear up any...
View ArticleA Complete Guide to Working With Cookies in Go
In this post we're going to run through how to use cookies in your Go web application to persist data between HTTP requests for a specific client. We'll start simple, and slowly build up a working...
View ArticleThe ‘fat service’ pattern for Go web applications
In this post I'd like to talk about one of my favorite architectural patterns for building web applications and APIs in Go. It's kind of a mix between the service object and fat model patterns — so I...
View ArticleFlow: A delightfully tiny but powerful HTTP router for Go
Last year I wrote a new HTTP router for Go called Flow. I've been using it in production on this site and in a couple of other projects since, and I'm pretty happy with how it's working out so decided...
View ArticleHow to use go run to manage tool dependencies
When you're working on a project it's common for there to be some developer tooling dependencies. These aren't code dependencies, but rather tools that you run on as part of the development, testing,...
View ArticleQuick tip: Easy test assertions with Go generics
Now that Go 1.18 has been released with support for generics, it's easier than ever to create helper functions for your test assertions. Using helpers for your test assertions can help to: Make your...
View Article