From d03bf1aa1465ce7b87382b058aac05aac20e3dba Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Wed, 23 Aug 2023 16:30:47 +0300 Subject: [PATCH] insert request id in context Signed-off-by: Vasiliy Tolstov --- requestid.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/requestid.go b/requestid.go index 3609c03..e4be5c5 100644 --- a/requestid.go +++ b/requestid.go @@ -10,6 +10,8 @@ import ( "go.unistack.org/micro/v3/util/id" ) +var XRequestIDKey struct{} + // DefaultMetadataKey contains metadata key var DefaultMetadataKey = textproto.CanonicalMIMEHeaderKey("x-request-id") @@ -40,7 +42,8 @@ var DefaultMetadataFunc = func(ctx context.Context) (context.Context, error) { omd.Set(DefaultMetadataKey, v) ctx = metadata.NewIncomingContext(ctx, imd) ctx = metadata.NewOutgoingContext(ctx, omd) - return ctx, nil + + return context.WithValue(ctx, XRequestIDKey, v), nil } type wrapper struct {