metadata: use new helper
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
parent
0a5b34a07b
commit
a59aae760f
@ -43,10 +43,7 @@ func (md Metadata) Del(key string) {
|
|||||||
|
|
||||||
// Copy makes a copy of the metadata
|
// Copy makes a copy of the metadata
|
||||||
func Copy(md Metadata) Metadata {
|
func Copy(md Metadata) Metadata {
|
||||||
if len(md) == 0 {
|
nmd := New(len(md))
|
||||||
return make(Metadata, DefaultMetadataSize)
|
|
||||||
}
|
|
||||||
nmd := make(Metadata, len(md))
|
|
||||||
for key, val := range md {
|
for key, val := range md {
|
||||||
nmd.Set(key, val)
|
nmd.Set(key, val)
|
||||||
}
|
}
|
||||||
@ -56,7 +53,7 @@ func Copy(md Metadata) Metadata {
|
|||||||
func Del(ctx context.Context, key string) context.Context {
|
func Del(ctx context.Context, key string) context.Context {
|
||||||
md, ok := FromContext(ctx)
|
md, ok := FromContext(ctx)
|
||||||
if !ok {
|
if !ok {
|
||||||
md = make(Metadata, DefaultMetadataSize)
|
md = New(0)
|
||||||
}
|
}
|
||||||
md.Del(key)
|
md.Del(key)
|
||||||
return context.WithValue(ctx, metadataKey{}, md)
|
return context.WithValue(ctx, metadataKey{}, md)
|
||||||
@ -66,7 +63,7 @@ func Del(ctx context.Context, key string) context.Context {
|
|||||||
func Set(ctx context.Context, key, val string) context.Context {
|
func Set(ctx context.Context, key, val string) context.Context {
|
||||||
md, ok := FromContext(ctx)
|
md, ok := FromContext(ctx)
|
||||||
if !ok {
|
if !ok {
|
||||||
md = make(Metadata, DefaultMetadataSize)
|
md = New(0)
|
||||||
}
|
}
|
||||||
md.Set(key, val)
|
md.Set(key, val)
|
||||||
return context.WithValue(ctx, metadataKey{}, md)
|
return context.WithValue(ctx, metadataKey{}, md)
|
||||||
|
Loading…
Reference in New Issue
Block a user