The go get tool
The go get
tool allows you to download and use different libraries. While Go comes with a wide range of packages by default, it is dwarfed by the number of third-party packages that are available. These provide extra functionality that you can use in your code to enhance it. However, for your code to make use of these packages, you need to have them on your computer so that the compiler can include them when compiling your code. To download these packages, you can use the go
get
tool.
Exercise 20.08 – implementing the go get tool
In this exercise, you will learn how to download a third-party package using go get
. Let’s get started:
- Create a new directory called
Exercise20.08
. Within that directory, create a new file calledmain.go
. - Run the following two commands to create the go module for this exercise:
go mod init go mod tidy
- Add the following code to the
main.go
file you created:package main import ( "fmt" ...