Rework use of context
This commit is contained in:
22
context/context.go
Normal file
22
context/context.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package context
|
||||
|
||||
import (
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
type key int
|
||||
|
||||
const (
|
||||
mdKey = key(0)
|
||||
)
|
||||
|
||||
type MetaData map[string]string
|
||||
|
||||
func GetMetaData(ctx context.Context) (MetaData, bool) {
|
||||
md, ok := ctx.Value(mdKey).(MetaData)
|
||||
return md, ok
|
||||
}
|
||||
|
||||
func WithMetaData(ctx context.Context, md MetaData) context.Context {
|
||||
return context.WithValue(ctx, mdKey, md)
|
||||
}
|
Reference in New Issue
Block a user