Several recipes throughout this book make use of the context package. This recipe will explore the basics of creating and managing contexts. A good reference for understanding context is https://blog.golang.org/context. Since this blog post was written, context moved from net/context to a package called context. This still occasionally causes problems when interacting with third-party libraries such as GRPC.
This recipe will explore setting and getting values for contexts, cancellation, and timeouts.
How to do it...
These steps cover writing and running your application:
- From your Terminal or console application,createa new directory called~/projects/go-programming-cookbook/chapter10/contextand navigate to it.
- Run the following command:
$ go mod init github.com/PacktPublishing/Go-Programming-Cookbook-Second-Edition/chapter10/context
You should see a file called...