gocommon/commonctx/request_id.go
Matthieu 'JP' DERASSE 77b4351ef1
All checks were successful
continuous-integration/drone/push Build is passing
feat(error): Create api error. WIP
2023-08-22 19:59:44 +00:00

24 lines
536 B
Go

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 {
requestIDStr, cast := requestID.(string)
if !cast {
return nil
}
return &requestIDStr
}
return nil
}