Skip to main content

exploring the latest release candidate of golang 1.21

·3 mins

Exciting developments are on the horizon for the Go programming language as it enters the release candidate phase of its latest version Go 1.21. Among the most highly anticipated addition is the introduction of generics support to the standard library. This new release not only brings generics to the standard library but it also includes changes to the Golang’s tooling, a new structured logging package, an experimental wasi port and more. In this article, we delve into the exciting features of this release candidate, highlighting some of my favourite new features coming in Go 1.21.

Go Toolchain #

The Go toolchain is a collection of tools that are used to compile, test, and run Go code. With the upcoming release of Go 1.21, developers will gain the ability to select their preferred version. This functionality can be leveraged by adding go or toolchain lines either to the projects go.mod or files. Consequently, the go toolchain will seamlessly download, cache and utilise the specified version. If desired, automatic toolchain switching can be disabled. However, in such cases, the go command will refuse to execute within a directory containing a go.mod or file that specifies a newer version the currently running one. In the future, I plan to write more articles that delve into the this new feature in more depth and the possibilities it enables. For more information on the new go toolchain, check out the documentation.

min, max, and clear built-in functions #

One notable addition in this release is the introduction of three new built-in functions: min, max, and clear. These functions aim to provide developers with enhanced convenience and flexibility when working with data.

The min and max functions are designed to simplify the process of finding the minimum and maximum values for the given values. With the introduction of these new functions, finding the smallest or largest values becomes a straightforward task, reducing both coding effort and potential errors.

Additionally, the clear function offers a convenient way to delete or zero out all elements. This can be particularly useful in scenarios where the reusability of data structures is crucial, allowing developers to easily initalise or reset them without the need for manual iteration or complex workarounds. Check out the documentation for the new min/max and clear functions.

Structured Logging with log/slog #

The log/slog library is a new structured logging package that is being introduced in Go 1.21. This new logger brings immense convenience and eliminates the need for external libraries like zap or zerolog. With the introduction of this new package, developers will be able to easily log structured data without the need for additional dependencies. Developers will no longer need to spend time evulating and integrating external logging libraries, instead they can simply use the log/slog library to log structured data. Open source libraries and projects will also benefit from this new package as it will allow them to provide structured logging without the need for external dependencies or interfaces to other logging libraries. More information about the new log/slog package can be found here.

More! #

In this article, I have provided an overview of some of the features included in Go 1.21. However, it is important to note that there are numerous other exciting additions in this release. For a comprehensive understanding of the upcoming release, I recommend visiting the official Go blog and release notes for detailed information about the new functionalities and enhancements coming in Go 1.21.