metadata: add Pairs helper func

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
2021-02-22 00:08:05 +03:00
parent b505455f7c
commit 3247da3dd0
3 changed files with 48 additions and 2 deletions

View File

@@ -108,7 +108,11 @@ func NewOutgoingContext(ctx context.Context, md Metadata) context.Context {
}
// AppendOutgoingContext apends new md to context
func AppendOutgoingContext(ctx context.Context, md Metadata) context.Context {
func AppendOutgoingContext(ctx context.Context, kv ...string) context.Context {
md, ok := Pairs(kv...)
if !ok {
return ctx
}
omd, ok := FromOutgoingContext(ctx)
if !ok {
return NewOutgoingContext(ctx, md)
@@ -120,7 +124,11 @@ func AppendOutgoingContext(ctx context.Context, md Metadata) context.Context {
}
// AppendIncomingContext apends new md to context
func AppendIncomingContext(ctx context.Context, md Metadata) context.Context {
func AppendIncomingContext(ctx context.Context, kv ...string) context.Context {
md, ok := Pairs(kv...)
if !ok {
return ctx
}
omd, ok := FromIncomingContext(ctx)
if !ok {
return NewIncomingContext(ctx, md)