]> Cypherpunks repositories - gostls13.git/commitdiff
context: discourage use of basic types as keys in WithValue
authorMatt Layher <mdlayher@gmail.com>
Fri, 30 Sep 2016 21:23:24 +0000 (17:23 -0400)
committerBrad Fitzpatrick <bradfitz@golang.org>
Fri, 30 Sep 2016 21:30:29 +0000 (21:30 +0000)
Fixes #17302

Change-Id: I375d5d4f2714ff415542f4fe56a548e53c5e8ba6
Reviewed-on: https://go-review.googlesource.com/30134
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/context/context.go

index 3afa3e90d2cabb03af1a2aedf869b2c42d473ef8..41a5cefef9365fe4c8cdf762a6d87730bb76e74a 100644 (file)
@@ -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")