Introduction This year I set a personal goal of walking for a total of 1,000 kilometers and I’m proud to say I’m close to hitting that goal. I’ve been tracking all the different routes I take in an app named Strava. One nice feature of Strava is that the app provides access to the raw data in a format called GPX. Starva can visualize the route in their app, but I wanted to try and perform my own visualization.
Continue readingIntroduction Prior to coding in Go, I was writing software in C#. In C# enumerations can be declared and the associated type can be used in functions and as fields in a struct. The compiler won’t allow a value of the enumerated type to be passed or set that doesn’t belong to the defined set. This is something that I have missed since coding in Go.
Go doesn’t have enumerations and it can be a problem at times when you want type safety for a well-defined set of values.
Continue readingSeries Here are all the posts in this series about the slices package.
Binary Search Clip, Clone, and Compact Compare Contains, Delete, and Equal Introduction In the last post of this series, I discussed the Compare API from the slices package. In this post, I will share how the Contains, Delete, and Equal APIs work.
Contains The Contains API reports whether a specified value exists in a specified collection.
Listing 1
Continue readingSeries Here are all the posts in this series about the slices package.
Binary Search Clip, Clone, and Compact Compare Contains, Delete, and Equal Introduction In the last post of this series I discussed the Clip, Clone, and Compact APIs from the slices package. In this post, I will share how the Compare and CompareFunc APIs work.
Compare The Compare API can be used to compare two slices and determine if the slices are equal or which one is shorter.
Continue readingSeries Here are all the posts in this series about the slices package.
Binary Search Clip, Clone, and Compact Compare Contains, Delete, and Equal Introduction In the first post of this series, I discussed the binary search API from the slices package that is now part of the standard library with the release of version 1.21. In this post, I will share how the Clip, Clone, and Compact APIs work.
Continue readingSeries Here are all the posts in this series about the slices package.
Binary Search Clip, Clone, and Compact Compare Contains, Delete, and Equal Introduction Go’s most important data structure is the slice and it was designed from the beginning to be mechanically sympathetic with the hardware. To learn more about that, check out Bill Kennedy’s Ultimate Go video. Thanks to the introduction of generics in Go 1.18, the language team has been experimenting with a new package called slices.
Continue readingIntroduction When a CPU needs to access a piece of data, the data needs to travel into the processor from main memory.
The architecture looks something like this:
Figure 1: CPU Cache
Figure 1 shows the different layers of memory a piece of data has to travel to be accessible by the processor. Each CPU has its own L1 and L2 cache, and the L3 cache is shared among all CPUs.
Continue readingApril 3, 2023Ardan Labs
From the Ardan Community
Introduction In episode 9, Miki discussed how a command flag can be decoded into a user defined type with the Value interface. As a recap, the Value interface consists of two methods: one for serializing the underlying concrete type and one for deserializing a string into an object. To put this interface to the test, Miki wrote a command that had a flag to specify a network address. While implementing the Set method of the Value interface, Miki demonstrated how to add validation for your program’s flags.
Continue reading March 27, 2023Ardan Labs
From the Ardan Community
Introduction In episode 8, Miki developed a Go HTTP client that had a method to check the health of a theoretical API. The method would construct the request URL and return an error based on the response code received from the server. Miki then created a type that would mock Go’s http.RoundTripper interface and replace his client’s transport with said type to test it. To improve the efficacy, Miki’s stub will simulate an erroneous response to see if his client’s Health method is working as intended.
Continue reading March 20, 2023Ardan Labs
From the Ardan Community
Introduction In episode 7, Miki discussed design considerations to keep in mind while creating interfaces in Go with the first idea he proposed being that an interface should represent what we need from a type, and not what is stored on the type. To add some clarity to this thought, Miki explained how the io.Reader and io.Writer interfaces each require one method to be implemented although the underlying concrete type may store more information.
Continue reading