Commit c5f064ee authored by Matt Layher's avatar Matt Layher Committed by Brad Fitzpatrick

context: discourage use of basic types as keys in WithValue

Fixes #17302

Change-Id: I375d5d4f2714ff415542f4fe56a548e53c5e8ba6
Reviewed-on: https://go-review.googlesource.com/30134Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
parent ca04091f
......@@ -443,7 +443,9 @@ func WithTimeout(parent Context, timeout time.Duration) (Context, CancelFunc) {
// Use context Values only for request-scoped data that transits processes and
// APIs, not for passing optional parameters to functions.
//
// The provided key must be comparable.
// The provided key must be comparable and should not be
// of type string or any other built-in type.
// Users of WithValue should define their own types for keys.
func WithValue(parent Context, key, val interface{}) Context {
if key == nil {
panic("nil key")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment