Go errors with codes

In a hurry 🏃? Jump to the conclusion After some discussion on Reddit, I decided to write this blog post on how to have Go errors containing codes you can use in calling layers. This is the case for example if you want to have the HTTP status code contained in an error created in your database package. Let’s start with some base code showing how this works. You have two files:...

September 18, 2021 · 2 min · Quentin McGaw

Wrap Go errors like it's Christmas!

In a hurry 🏃? Jump to the conclusion It took me months if not years to figure out the best way to wrap errors in Go. This was even more critical when developing public Go APIs where a user should be able to check for your (returned) errors. Global variables and errors NEVER USE GLOBAL VARIABLES!… except for errors which are meant to be constants. For example: var ErrUserNotFound = errors....

September 15, 2021 · 4 min · Quentin McGaw