micro/context/context.go

23 lines
359 B
Go
Raw Normal View History

2015-05-23 13:53:40 +03:00
package context
import (
"golang.org/x/net/context"
)
type key int
const (
mdKey = key(0)
)
2015-05-27 00:39:48 +03:00
type Metadata map[string]string
2015-05-23 13:53:40 +03:00
2015-05-27 00:39:48 +03:00
func GetMetadata(ctx context.Context) (Metadata, bool) {
md, ok := ctx.Value(mdKey).(Metadata)
2015-05-23 13:53:40 +03:00
return md, ok
}
2015-05-27 00:39:48 +03:00
func WithMetadata(ctx context.Context, md Metadata) context.Context {
2015-05-23 13:53:40 +03:00
return context.WithValue(ctx, mdKey, md)
}