Merge pull request 'removed create empty out/ingoing metadata' (#364) from devstigneev/micro:v3 into v3
Reviewed-on: #364 Reviewed-by: Василий Толстов <v.tolstov@unistack.org>
This commit is contained in:
commit
94e8f90f00
@ -55,10 +55,7 @@ func NewContext(ctx context.Context, md Metadata) context.Context {
|
|||||||
if ctx == nil {
|
if ctx == nil {
|
||||||
ctx = context.Background()
|
ctx = context.Background()
|
||||||
}
|
}
|
||||||
ctx = context.WithValue(ctx, mdKey{}, &rawMetadata{md})
|
return context.WithValue(ctx, mdKey{}, &rawMetadata{md})
|
||||||
ctx = context.WithValue(ctx, mdIncomingKey{}, &rawMetadata{})
|
|
||||||
ctx = context.WithValue(ctx, mdOutgoingKey{}, &rawMetadata{})
|
|
||||||
return ctx
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetOutgoingContext modify outgoing context with given metadata
|
// SetOutgoingContext modify outgoing context with given metadata
|
||||||
@ -90,11 +87,7 @@ func NewIncomingContext(ctx context.Context, md Metadata) context.Context {
|
|||||||
if ctx == nil {
|
if ctx == nil {
|
||||||
ctx = context.Background()
|
ctx = context.Background()
|
||||||
}
|
}
|
||||||
ctx = context.WithValue(ctx, mdIncomingKey{}, &rawMetadata{md})
|
return context.WithValue(ctx, mdIncomingKey{}, &rawMetadata{md})
|
||||||
if v, ok := ctx.Value(mdOutgoingKey{}).(*rawMetadata); !ok || v == nil {
|
|
||||||
ctx = context.WithValue(ctx, mdOutgoingKey{}, &rawMetadata{})
|
|
||||||
}
|
|
||||||
return ctx
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewOutgoingContext creates a new context with outcoming metadata attached
|
// NewOutgoingContext creates a new context with outcoming metadata attached
|
||||||
@ -102,11 +95,7 @@ func NewOutgoingContext(ctx context.Context, md Metadata) context.Context {
|
|||||||
if ctx == nil {
|
if ctx == nil {
|
||||||
ctx = context.Background()
|
ctx = context.Background()
|
||||||
}
|
}
|
||||||
ctx = context.WithValue(ctx, mdOutgoingKey{}, &rawMetadata{md})
|
return context.WithValue(ctx, mdOutgoingKey{}, &rawMetadata{md})
|
||||||
if v, ok := ctx.Value(mdIncomingKey{}).(*rawMetadata); !ok || v == nil {
|
|
||||||
ctx = context.WithValue(ctx, mdIncomingKey{}, &rawMetadata{})
|
|
||||||
}
|
|
||||||
return ctx
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// AppendOutgoingContext apends new md to context
|
// AppendOutgoingContext apends new md to context
|
||||||
|
@ -80,6 +80,13 @@ func TestPassing(t *testing.T) {
|
|||||||
ctx = NewIncomingContext(ctx, md1)
|
ctx = NewIncomingContext(ctx, md1)
|
||||||
testCtx(ctx)
|
testCtx(ctx)
|
||||||
md, ok := FromOutgoingContext(ctx)
|
md, ok := FromOutgoingContext(ctx)
|
||||||
|
if ok {
|
||||||
|
t.Fatalf("create outgoing context")
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx = NewOutgoingContext(ctx, New(1))
|
||||||
|
testCtx(ctx)
|
||||||
|
md, ok = FromOutgoingContext(ctx)
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Fatalf("missing metadata from outgoing context")
|
t.Fatalf("missing metadata from outgoing context")
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user