-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcontext.go
More file actions
35 lines (26 loc) · 804 Bytes
/
context.go
File metadata and controls
35 lines (26 loc) · 804 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package bgo
import (
"context"
)
type innerKey string
func (c innerKey) String() string {
return "bgo inner context key: " + string(c)
}
func withValue(ctx context.Context, key string, v interface{}) context.Context {
return context.WithValue(ctx, innerKey(key), v)
}
func value(ctx context.Context, key string) interface{} {
return ctx.Value(innerKey(key))
}
type outerKey string
func (c outerKey) String() string {
return "bgo outer context key: " + string(c)
}
// WithValue create a new context with a specific key & value
func WithValue(ctx context.Context, key string, v interface{}) context.Context {
return context.WithValue(ctx, outerKey(key), v)
}
// Value get value with a specific key
func Value(ctx context.Context, key string) interface{} {
return ctx.Value(outerKey(key))
}