Understanding Go’s Context Type

Go provides a package called context that is useful for two purposes, as outlined here:

  • Canceling a chain of function calls after some event (such as a timeout)

  • Passing information through a chain of function calls (such as user information)

A Context object is usually created in either main() or at the point of ingestion of some request (such as an RPC or HyperText Transfer Protocol (HTTP) request).

Get hands-on with 1400+ tech skills courses.