metadata: add Merge func

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
2021-01-23 00:09:07 +03:00
parent c7bafecce3
commit 202a942eef
3 changed files with 30 additions and 11 deletions

View File

@@ -35,15 +35,5 @@ func MergeContext(ctx context.Context, pmd Metadata, overwrite bool) context.Con
if !ok {
return context.WithValue(ctx, metadataKey{}, Copy(pmd))
}
nmd := Copy(md)
for key, val := range pmd {
if _, ok := nmd[key]; ok && !overwrite {
// skip
} else if val != "" {
nmd.Set(key, val)
} else {
nmd.Del(key)
}
}
return context.WithValue(ctx, metadataKey{}, nmd)
return context.WithValue(ctx, metadataKey{}, Merge(md, pmd, overwrite))
}