Learn to code by coding - try our free CS courses

How to Use Mutexes in Go

exclude

Golang is King when it comes to concurrency. No other language has so many tools right out of the box, and one of those tools is the standard library’s sync.Mutex{}. Mutexes let us safely control access to data across multiple goroutines. What problem do mutexes solve? We don’t want multiple threads accessing the same memory …

Read more

Best Practices for Interfaces in Go

block interfaces

Interfaces in Go allow us to treat different types as the same data type temporarily because both types implement the same kind of behavior. They’re central to a Go programmer’s toolbelt and are often used improperly by new Go developers, which leads to unreadable and often buggy code. What is an interface in Golang? In …

Read more

Wrapping Errors in Go – How to Handle Nested Errors

photo 1495863367063 b9ac3e6394f7

Errors in Go are a hot topic. Many newcomers to the language immediately level their first criticism, “errors in go are clunky! Let me just use try/catch!” This criticism is well-meaning but misguided. The paradigm of errors as a type, rather than something to be thrown and cause panics, allows for more control of how …

Read more

JWT Authentication in Golang

logo 400

Go is becoming very popular for backend web development, and JWT’s are one of the most popular ways to handle authentication on API requests. In this article, we’ll go over the basics of JWT’s and how to implement a secure authentication strategy in Go! What is a JWT? JSON Web Tokens are an open, industry-standard RFC …

Read more

BitBanged SPI in Go, An Explanation

1 5WD0gV6autEIzv8GMkc5gQ

I’m going to focus mostly on some design decisions and also how I went about writing an SPI interface using Go on a Raspberry Pi. I assume my readers have a basic understanding of what a Raspberry Pi is, and how basic electronics work. If not, read on anyway and I will be sure to …

Read more

Top 6 Golang Logging Best Practices

guest writing on table

Let’s discuss a few rules of thumb for logging in Go, as well as some features you may not have heard of that can make debugging easier. Best practices for logging in Go are not so obvious and sometimes we need to look closer to see what is the best choice, considering the unique situation …

Read more

How to Create Constant Maps, Slices, & Arrays in Golang

How to Create Constant Maps and Slices in Go

For the most part, I’ve found that Go developers are pretty good at using global constants for configuration rather than global variables. However, a problem arises when we want a constant version of some of the more complex types. The Go compiler does not allow us to create array, map, or slice constants. After realizing …

Read more

The Proper Use of Pointers in Go (Golang)

photo 1497005367839 6e852de72767

Go has become increasingly popular in recent years, especially in my local area. It has been consistently displacing other backend languages like Ruby, Python, C# and Java. Go is wanted for its simplicity, explicitness, speed, and low memory consumption. Many developers that are new to the language, or new to a language that can handle …

Read more