1
0
mirror of https://github.com/go-micro/go-micro.git synced 2025-08-04 21:42:57 +02:00

Strip MetadataKey global var

This commit is contained in:
Asim Aslam
2020-04-12 11:16:08 +01:00
parent cf67d460b7
commit 962588b649
4 changed files with 15 additions and 15 deletions

View File

@ -6,7 +6,7 @@ import (
"strings"
)
type MetadataKey struct{}
type metadataKey struct{}
// Metadata is our way of representing request headers internally.
// They're used at the RPC level and translate back and forth
@ -57,7 +57,7 @@ func Set(ctx context.Context, k, v string) context.Context {
} else {
md[k] = v
}
return context.WithValue(ctx, MetadataKey{}, md)
return context.WithValue(ctx, metadataKey{}, md)
}
// Get returns a single value from metadata in the context
@ -80,7 +80,7 @@ func Get(ctx context.Context, key string) (string, bool) {
// FromContext returns metadata from the given context
func FromContext(ctx context.Context) (Metadata, bool) {
md, ok := ctx.Value(MetadataKey{}).(Metadata)
md, ok := ctx.Value(metadataKey{}).(Metadata)
if !ok {
return nil, ok
}
@ -96,7 +96,7 @@ func FromContext(ctx context.Context) (Metadata, bool) {
// NewContext creates a new context with the given metadata
func NewContext(ctx context.Context, md Metadata) context.Context {
return context.WithValue(ctx, MetadataKey{}, md)
return context.WithValue(ctx, metadataKey{}, md)
}
// MergeContext merges metadata to existing metadata, overwriting if specified
@ -104,7 +104,7 @@ func MergeContext(ctx context.Context, patchMd Metadata, overwrite bool) context
if ctx == nil {
ctx = context.Background()
}
md, _ := ctx.Value(MetadataKey{}).(Metadata)
md, _ := ctx.Value(metadataKey{}).(Metadata)
cmd := make(Metadata, len(md))
for k, v := range md {
cmd[k] = v
@ -118,5 +118,5 @@ func MergeContext(ctx context.Context, patchMd Metadata, overwrite bool) context
delete(cmd, k)
}
}
return context.WithValue(ctx, MetadataKey{}, cmd)
return context.WithValue(ctx, metadataKey{}, cmd)
}