add metadata.Get(context, key) as short hand
This commit is contained in:
parent
5ffe367cae
commit
65b1283459
@ -21,6 +21,16 @@ func Copy(md Metadata) Metadata {
|
|||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get returns a single value from metadata in the context
|
||||||
|
func Get(ctx context.Context, key string) (string, bool) {
|
||||||
|
md, ok := FromContext(ctx)
|
||||||
|
if !ok {
|
||||||
|
return "", ok
|
||||||
|
}
|
||||||
|
val, ok := md[key]
|
||||||
|
return val, ok
|
||||||
|
}
|
||||||
|
|
||||||
// FromContext returns metadata from the given context
|
// FromContext returns metadata from the given context
|
||||||
func FromContext(ctx context.Context) (Metadata, bool) {
|
func FromContext(ctx context.Context) (Metadata, bool) {
|
||||||
md, ok := ctx.Value(metaKey{}).(Metadata)
|
md, ok := ctx.Value(metaKey{}).(Metadata)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user