Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make requestid name consistent with JSON standart #182

Merged
merged 1 commit into from
Feb 7, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions requestid/requestid.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import (
)

// DefaultRequestIDKey is the metadata key name for request ID
const DefaultRequestIDKey = "Request-Id"
const (
DeprecatedRequestIDKey = "Request-Id"
DefaultRequestIDKey = "request_id"
)

// HandleRequestID either extracts a existing and valid request ID from the context or generates a new one
func HandleRequestID(ctx context.Context) (reqID string) {
Expand All @@ -29,9 +32,16 @@ func newRequestID() string {
}

// FromContext returns the Request-Id information from ctx if it exists.
func FromContext(ctx context.Context) (reqID string, exists bool) {
reqID, exists = gateway.Header(ctx, DefaultRequestIDKey)
return
func FromContext(ctx context.Context) (string, bool) {
if reqID, ok := gateway.Header(ctx, DefaultRequestIDKey); ok {
return reqID, ok
}

if reqID, ok := gateway.Header(ctx, DeprecatedRequestIDKey); ok {
return reqID, ok
}

return "", false
}

// NewContext creates a new context with Request-Id attached if not exists.
Expand Down