From 4cb50e86920028e94d651dbfe40b208ea2476142 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Wed, 5 May 2021 16:39:41 +0300 Subject: [PATCH] dont overwrite metadata Signed-off-by: Vasiliy Tolstov --- requestid.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/requestid.go b/requestid.go index 70154df..e4c2b5a 100644 --- a/requestid.go +++ b/requestid.go @@ -19,12 +19,12 @@ var ( // MetadataFunc wil be used if user not provide own func to fill metadata MetadataFunc = func(ctx context.Context) (context.Context, error) { md, ok := metadata.FromIncomingContext(ctx) - if ok { - if _, ok = md.Get(MetadataKey); ok { - return ctx, nil - } + if !ok { + md = metadata.New(1) + } + if _, ok = md.Get(MetadataKey); ok { + return ctx, nil } - md = metadata.New(1) id, err := uuid.NewRandom() if err != nil { return ctx, err