Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
parent
856aac4aa9
commit
eb534a46d0
@ -67,11 +67,12 @@ func (md Metadata) Del(keys ...string) {
|
||||
}
|
||||
|
||||
// Copy makes a copy of the metadata
|
||||
func Copy(md Metadata) Metadata {
|
||||
func Copy(md Metadata, exclude ...string) Metadata {
|
||||
nmd := make(Metadata, len(md))
|
||||
for k, v := range md {
|
||||
nmd[k] = v
|
||||
}
|
||||
nmd.Del(exclude...)
|
||||
return nmd
|
||||
}
|
||||
|
||||
|
@ -189,3 +189,14 @@ func TestMetadataContext(t *testing.T) {
|
||||
t.Errorf("Expected metadata length 1 got %d", i)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCopy(t *testing.T) {
|
||||
md := New(2)
|
||||
md.Set("key1", "val1", "key2", "val2")
|
||||
nmd := Copy(md, "key2")
|
||||
if len(nmd) != 1 {
|
||||
t.Fatal("Copy exclude not works")
|
||||
} else if nmd["Key1"][0] != "val1" {
|
||||
t.Fatal("Copy exclude not works")
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user