don't just overwrite the context metadata, append if already exists

This commit is contained in:
Asim 2015-11-26 20:35:50 +00:00
parent bcff71167c
commit 4fa909a3c7

View File

@ -18,5 +18,12 @@ func GetMetadata(ctx context.Context) (Metadata, bool) {
}
func WithMetadata(ctx context.Context, md Metadata) context.Context {
if emd, ok := ctx.Value(mdKey).(Metadata); ok {
for k, v := range emd {
if _, ok := md[k]; !ok {
md[k] = v
}
}
}
return context.WithValue(ctx, mdKey, md)
}