-
Notifications
You must be signed in to change notification settings - Fork 18.7k
Description
The context package provides a standard interface for passing request-scoped values, deadlines, and cancelation information across package boundaries. Examples of request-scoped values include authentication information, golang.org/x/net/trace.Traces, and Dapper-like distributed tracing IDs. Context is widely used: godoc.org lists 1500+ imports. Context is a critical element in RPC systems like Go-kit's Endpoint interface and gRPC Go.
We (@Sajmani and @bradfitz) would like to incorporate Context into standard library packages (see list below). Standard library packages cannot depend on external packages, so we propose moving the context package into the standard library as package "context".
One complication with moving this package is that interfaces that currently mention golang.org/x/net/context.Context will not be satisfied by implementations that use context.Context. For example, gRPC service implementations will fail to compile if we change the Go protocol compiler to use context.Context. We will need to provide some way to manage this transition.
Potential uses of Context in the standard library:
- Add Context to http.Request to support canceling HTTP requests and passing request-scoped values
- Add Context to net.Dialer to support canceling Dial
- Add Context to functions in database/sql and interfaces in database/sql/driver to support canceling database operations and passing request-scoped values
- Generally, add Context to any function that supports cancelation and may be implemented using RPCs