Meta key change

This commit is contained in:
Asim 2016-01-28 18:24:56 +00:00
parent 9ae0956cea
commit b9f4e17d4c

View File

@ -4,26 +4,22 @@ import (
"golang.org/x/net/context" "golang.org/x/net/context"
) )
type contextKeyT string type metaKey struct{}
const (
contextKey = contextKeyT("github.com/micro/go-micro/metadata")
)
type Metadata map[string]string type Metadata map[string]string
func FromContext(ctx context.Context) (Metadata, bool) { func FromContext(ctx context.Context) (Metadata, bool) {
md, ok := ctx.Value(contextKey).(Metadata) md, ok := ctx.Value(metaKey{}).(Metadata)
return md, ok return md, ok
} }
func NewContext(ctx context.Context, md Metadata) context.Context { func NewContext(ctx context.Context, md Metadata) context.Context {
if emd, ok := ctx.Value(contextKey).(Metadata); ok { if emd, ok := ctx.Value(metaKey{}).(Metadata); ok {
for k, v := range emd { for k, v := range emd {
if _, ok := md[k]; !ok { if _, ok := md[k]; !ok {
md[k] = v md[k] = v
} }
} }
} }
return context.WithValue(ctx, contextKey, md) return context.WithValue(ctx, metaKey{}, md)
} }