Meta key change
This commit is contained in:
parent
9ae0956cea
commit
b9f4e17d4c
@ -4,26 +4,22 @@ import (
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
type contextKeyT string
|
||||
|
||||
const (
|
||||
contextKey = contextKeyT("github.com/micro/go-micro/metadata")
|
||||
)
|
||||
type metaKey struct{}
|
||||
|
||||
type Metadata map[string]string
|
||||
|
||||
func FromContext(ctx context.Context) (Metadata, bool) {
|
||||
md, ok := ctx.Value(contextKey).(Metadata)
|
||||
md, ok := ctx.Value(metaKey{}).(Metadata)
|
||||
return md, ok
|
||||
}
|
||||
|
||||
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 {
|
||||
if _, ok := md[k]; !ok {
|
||||
md[k] = v
|
||||
}
|
||||
}
|
||||
}
|
||||
return context.WithValue(ctx, contextKey, md)
|
||||
return context.WithValue(ctx, metaKey{}, md)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user