File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,23 @@ func WithCancel(parent Context) (ctx Context, cancel CancelFunc) {
14
14
return sync .WithCancel (parent )
15
15
}
16
16
17
+ // WithValue returns a copy of parent in which the value associated with key is
18
+ // val.
19
+ //
20
+ // Use context Values only for request-scoped data that transits processes and
21
+ // APIs, not for passing optional parameters to functions.
22
+ //
23
+ // The provided key must be comparable and should not be of type
24
+ // string or any other built-in type to avoid collisions between
25
+ // packages using context. Users of WithValue should define their own
26
+ // types for keys. To avoid allocating when assigning to an
27
+ // interface{}, context keys often have concrete type
28
+ // struct{}. Alternatively, exported context key variables' static
29
+ // type should be a pointer or interface.
30
+ func WithValue (parent Context , key , val interface {}) Context {
31
+ return sync .WithValue (parent , key , val )
32
+ }
33
+
17
34
func NewDisconnectedContext (ctx Context ) Context {
18
35
return sync .NewDisconnectedContext (ctx )
19
36
}
You can’t perform that action at this time.
0 commit comments