Merge pull request 'insert request id in context' (#101) from rr into master
Some checks failed
build / test (push) Failing after 1m30s
build / lint (push) Failing after 2m34s
codeql / analyze (go) (push) Failing after 3m9s

Reviewed-on: #101
This commit is contained in:
Василий Толстов 2023-08-23 16:34:27 +03:00
commit fdffd31ed3

View File

@ -10,6 +10,8 @@ import (
"go.unistack.org/micro/v4/util/id" "go.unistack.org/micro/v4/util/id"
) )
var XRequestIDKey struct{}
// DefaultMetadataKey contains metadata key x-request-id // DefaultMetadataKey contains metadata key x-request-id
var DefaultMetadataKey = textproto.CanonicalMIMEHeaderKey("x-request-id") var DefaultMetadataKey = textproto.CanonicalMIMEHeaderKey("x-request-id")
@ -38,6 +40,7 @@ var DefaultMetadataFunc = func(ctx context.Context) (context.Context, error) {
} }
imd.Set(DefaultMetadataKey, v) imd.Set(DefaultMetadataKey, v)
omd.Set(DefaultMetadataKey, v) omd.Set(DefaultMetadataKey, v)
ctx = context.WithValue(ctx, XRequestIDKey, v)
ctx = metadata.NewIncomingContext(ctx, imd) ctx = metadata.NewIncomingContext(ctx, imd)
ctx = metadata.NewOutgoingContext(ctx, omd) ctx = metadata.NewOutgoingContext(ctx, omd)
return ctx, nil return ctx, nil