A big part of programming is about making choices: What data type do I use? A map, a slice, something more fancy? Do I implement this using recursion or a loop? Should I pass a value or a pointer? How to determine the best choice? One way is to measure performance using benchmarks. Go has built-in support for benchmarking in the testing package. In this article you’ll see how benchmarks are structured, what to keep in mind when writing them and how to execute them.| Boost Your Go/Golang Skills, One Article at a Time.
In Go, testing HTTP handlers is more work than testing regular functions. Inputs must be wrapped in HTTP requests, and responses are written to http.ResponseWriter, rather than being returned directly. To make matters worse, handlers expect server-side requests, while it’s easy to mistakenly construct client-side requests. You’d almost give up on testing your handlers altogether. Please don’t. This article will discuss how we can use httptest to safely test HTTP handlers.| Boost Your Go/Golang Skills, One Article at a Time.
Go doesn’t offer a native set type, and the standard library doesn’t provide one either. So, how do you create sets in Go? You use a map. First, we’ll explore how maps can be used to implement sets. However, if your program relies heavily on sets, maps can quickly become tedious. That’s why, in the second part, we’ll introduce an open-source package that offers two convenient set implementations. Finally, since these solutions only work with comparable types, we’ll wrap up by expl...| Boost Your Go/Golang Skills, One Article at a Time.
Coming from other languages it can be surprising that Go does not support string interpolation. What do I mean by string interpolation? Well, take this snippet of PHP for example: $x = 49; $msg = "Hello world"; echo "The number is $x and the message is $msg"; When running the program PHP will evaluate the double quoted string and automatically replace the $x and $msg placeholders with the appropriate values. In the end, The number is 49 and the message is Hello world will be echoed.| Boost Your Go/Golang Skills, One Article at a Time.
I'm building a Go web application in public, join in on the fun!| www.willem.dev
2 Months in: All the major components are in place.| www.willem.dev
Learn how to use standard library interfaces to prevent sensitive data from leaking.| www.willem.dev
Read this article to find out how maps of functions allow your structure your code in a more declarative way.| www.willem.dev
If you're not yet comfortable with Go's type system and/or interfaces it can be a surprisingly difficult thing to wrap your head around. Read this post to learn how it works.| www.willem.dev
Are your tests growing out of control? This article explains how to deal with large structs in tests.| www.willem.dev
What is the point of using pointers to slices? This article discusses when it's a good idea to use pointers to slices.| www.willem.dev
What is the difference between a slice of pointers and a slice of values? And when should you use one or the other? This article explains.| www.willem.dev
Frustrated by time.Parse? You're not alone. This article will get you unstuck and moving again.| www.willem.dev
This article shows how to implement URL path parameters using the routing pattern wildcards introduced in Go 1.22.| www.willem.dev
Learn how to change the default JSON format of time.Time values in Go.| www.willem.dev
Why isn't comparing times or dates as easy as comparing numbers? Find out in this article.| www.willem.dev
Learn how Go measures time without stumbling on leap seconds, daylight saving time or timezone changes.| www.willem.dev
Learn how to think about time in Go. This article shows you how both types work together to represent moments in time.| www.willem.dev
This article explains anonymous structs for people who are unfamiliar with them.| www.willem.dev
Don't litter your code base with keys and/or type assertions. Add and get values from contexts in a type safe way.| www.willem.dev
Not every value should be stored in a Go context, this article examines why.| www.willem.dev
So far we have only created slices by slicing arrays, but there are more convenient ways to create new slices. In this article we will look at make, literals and re-slicing.| www.willem.dev
Append and copy are commonly used functions, but they can have some surprising behavior. This article helps you build a good intuition by showing you how to implement them yourself.| www.willem.dev
An introduction to arrays, slices and their relationship. Get a solid mental model by implementing your own slice.| www.willem.dev
Some guidance on choosing the right constructor for your context (and one thing you should never do).| www.willem.dev
How to handle and send "cancellation signals" using the context package in the standard library.| www.willem.dev
Implementing HTTP handlers in Go can be a bit of a chore. Make development a bit easier by building generic HTTP handlers.| www.willem.dev