Concatenating with strings.Builder Quickly in Golang

knot in string unsplash

The Go standard library makes concatenating strings easy. Concatenation is just a fancy word for adding strings together to make a larger string. For example, if we concatenate “hello”, ” ” and “world” we’d get “hello world”. The built-in fmt.Sprintf function takes a format and a variadic list of interfaces as input. The formatting option … Read more

The Ultimate Guide to JSON in Go

json data

Being a language built for the web, Go offers feature-rich support for working with JSON data. JSON (JavaScript Object Notation) is an unbelievably popular data interchange format whose syntax resembles simple JavaScript objects. It’s one of the most common ways for web applications to communicate. Before we get too far, let me mention that I recently … Read more

Search and Replace Strings in Golang – Top 5 Examples

replace lightbulb

Go has a powerful standard library that makes string manipulation easy right out of the box. One of the functions I use most often is the strings package’s Replace() function. strings.Replace() returns a copy of its input string after replacing all instances of the given substring with a new one. strings.Replace() signature Notes s is … Read more

How and Why to Write Enums in Go

list with pencil and paper

An enum (short for enumerator), is a set of named constant values. An enum is a powerful tool that allows developers to create complex sets of constants that have useful names yet simple and unique values. Before we get too far, let me mention that I recently launched Go Mastery, a hands-on Golang course. Give that course a … Read more

Splitting a String into a Slice in Golang

splitting a lemon

I can’t begin to tell you how often I split strings in Go. More often than not I’m just parsing a comma-separated list from an environment variable, and Go’s standard library gives us some great tools for that kind of manipulation. Before we get too far, let me mention that I recently launched Go Mastery, a … Read more

Backend Developers are UX Designers Too

design notebook

Too often I neglect the idea of UX design in backend work. The goal of user experience design is to give users a product that’s easy to use. In the world of front-end development, that typically means making it obvious how to navigate your site, using commonly-understood icons, or implementing well-contrasted colors for foreground and … Read more

All the Ways to Write for Loops in Go

loop architecture

A for loop executes a block of code repeatedly, and in Golang, there are several different ways to write one. The standard three-component loop For-range loop Range over slice Range over map Range over channel Range over string While loop Optional components loop Infinite loop Break from a loop Continue (skip to the next iteration) … Read more

Naming Variables the Right Way

yelling at computer

I’ve noticed that more and more often that bugs introduced into an existing codebase are due to the poor naming of variables way more often than I think you would expect. Someone uses a rateLimit variable expecting it to be denominated in seconds but instead, it’s in minutes, resulting in a wildly different polling schedule. … Read more