micro/context/context.go

23 lines
359 B
Go
Raw Normal View History

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