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