Golang Project Structure

Tutorials, tips and tricks for writing and structuring code in Go (with additional content for other programming languages)

idioms

Tag

Removing a Substring From a String in Go

A hand holding a pair of scissors.

In this blog post, we will explore several approaches that can be used to remove a substring from a larger string in Go, covering both basic cases and more complex scenarios. By the end of this guide, you should have a solid understanding of various ways to strip substrings from strings in Go and how […]

Getting the Directory of the Currently Running File in Go

An old-fashioned directory system with paper records in wooden drawers at a library.

When writing Go code, it can often be useful to know how to obtain the path to the directory where the file being currently executed is located. In this post, we’ll explore how to do this in Go and discuss some of the practical applications of this knowledge. Why Would I Need the Directory of […]

Discovering Whether One String Contains Another in Go

Five pieces of string arranged in a circular ring. Four of the rings of string each contain another ring of string.

When working with strings in Go, one common task is checking whether one string contains another. While this may seem straightforward, Go offers several methods, each with varying levels of complexity depending on the needs of your application. Whether you’re performing a case-sensitive substring search, looking for the index of a substring or diving into […]

Why Does Go Have So Many Different Kinds of For Loop?

A long-exposure photograph of a roundabout at night. No cars can be seen, but the trail left by their white and red headlights and taillights remains.

Anyone with experience of a C-based programming language will be immediately aware of how useful and fundamental for loops are. C also has while and do–while loops. JavaScript has a forEach method, which allows us to iterate over arrays, and it also has iterator objects. Go only really has the for loop. However, this single […]

Rob Pike’s Go Proverbs (Part Three)

A man with his legs crossed and his eyes closed. He is deep in meditation. The man is wearing a blue gown.

This is the third and final part of a three-part series on the Go proverbs that were devised by Rob Pike. We shall discuss and explain each of the remaining proverbs in turn. In this final instalment, we shall consider the remaining proverbs, discussing their meaning and their practical application. Each proverb reflects a core […]

Rob Pike’s Go Proverbs (Part Two)

Rob Pike, one of the creators of the Go programming language.

This is the second part of a three-part series discussing the Go proverbs that were devised by Rob Pike. (The original post is available to read, if you haven’t already. UPDATE: And the third and final post is now available to read too.) gofmt’s Style Is No One’s Favourite, Yet gofmt Is Everyone’s Favourite The […]

How to Test Code in Go

A health worker in a laboratory is performing a medical test using high-tech scientific equipment.

Testing should be considered an essential part of the software-development process, because it helps to ensure that our code works as expected when handling a wide range of reasonable values as input. So today we are going to look at how to write tests in Go, using the built-in syntax, and how to run the […]

Overview of JavaScript Promises

Two girls performing a "pinky promise" ritual with their hands.

Have you ever found yourself writing JavaScript code that becomes difficult to read because there are so many nested callbacks? Or do you get frustrated when your browser becomes unresponsive as it struggles to perform long-running operations in client-side code? Well, promises are designed to solve those problems! In this post we will discuss exactly […]