2023-01-29 15:56:09 +00:00
|
|
|
package commonctx
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
)
|
|
|
|
|
|
|
|
// AddRequestID will add the provided requestID in the context.
|
|
|
|
func AddRequestID(ctx context.Context, requestID string) context.Context {
|
|
|
|
return context.WithValue(ctx, ContextKey_RequestID, requestID)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetRequestID retrieve a requestID from the context.
|
|
|
|
func GetRequestID(ctx context.Context) *string {
|
|
|
|
if requestID := ctx.Value(ContextKey_RequestID); requestID != nil {
|
2023-08-21 07:08:54 +00:00
|
|
|
requestIDStr, cast := requestID.(string)
|
|
|
|
if !cast {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return &requestIDStr
|
2023-01-29 15:56:09 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|