aboutsummaryrefslogtreecommitdiff
path: root/src/context
diff options
context:
space:
mode:
authorMatt Layher <mdlayher@gmail.com>2016-09-30 17:23:24 -0400
committerBrad Fitzpatrick <bradfitz@golang.org>2016-09-30 21:30:29 +0000
commitc5f064ee49e98c00c7959fdf095e2c61ff0747b8 (patch)
tree3eae636fda011ccdfebcab4fc9cc251154b9d21b /src/context
parentca04091f5be4134291142cc4e7e577d0f627e788 (diff)
downloadgo-c5f064ee49e98c00c7959fdf095e2c61ff0747b8.tar.gz
go-c5f064ee49e98c00c7959fdf095e2c61ff0747b8.zip
context: discourage use of basic types as keys in WithValue
Fixes #17302 Change-Id: I375d5d4f2714ff415542f4fe56a548e53c5e8ba6 Reviewed-on: https://go-review.googlesource.com/30134 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'src/context')
-rw-r--r--src/context/context.go4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/context/context.go b/src/context/context.go
index 3afa3e90d2..41a5cefef9 100644
--- a/src/context/context.go
+++ b/src/context/context.go
@@ -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")