Documentation ¶
Index ¶
- Variables
- func AddCorrelationIDToRequest(ctx context.Context, req *http.Request, options CorrelationIDOptions) (*http.Request, error)
- func ContextWithCID(ctx context.Context, correlationID string, cidGenerator CorrelationIDGenerator) (context.Context, error)
- func FromContext[T any](key contextKey, ctx context.Context) (T, error)
- func GetCID(ctx context.Context) (string, error)
- type CorrelationIDGenerator
- type CorrelationIDHeaderFn
- type CorrelationIDOptions
- type Service
Constants ¶
This section is empty.
Variables ¶
var ( ErrContextIncompatibleType = errors.New("value from context did not match expected type") ErrContextValueNotFound = errors.New("context value not found") )
Functions ¶
func AddCorrelationIDToRequest ¶
func AddCorrelationIDToRequest(ctx context.Context, req *http.Request, options CorrelationIDOptions) (*http.Request, error)
AddCorrelationIDToRequest - For http clients. Adds a CorrelationID, from the given context, as a request Header to the request. If the context does not contain an existing CorrelationID, a new one will be generated using the correlationIDGeneratorFn provided. Note, If context or request are null, new ones will be returned
func ContextWithCID ¶
func ContextWithCID(ctx context.Context, correlationID string, cidGenerator CorrelationIDGenerator) (context.Context, error)
ContextWithCID adds the correlation id to the given context. Context is immutable so a new context is returned. If not correlation ID exists, a new one is generated, using the provided correlation id generator.
func FromContext ¶
FromContext - Get value from context
Types ¶
type CorrelationIDGenerator ¶
type CorrelationIDHeaderFn ¶
CorrelationIDHeaderFn - allows users of the lib to use their own correlation id http header name strategy e.g. x-correlation-id, trace-id, request-id, etc.. Allows clients to load the http header name from the ENV, config file, etc...
type CorrelationIDOptions ¶
type CorrelationIDOptions struct { CorrelationIDHttpHeaderFn CorrelationIDHeaderFn CorrelationIDGeneratorFn CorrelationIDGenerator }
CorrelationIDOptions Struct to be passed into tracr methods to allow retrieval of the preferred correlation id http header name, e.g. x-correlation-id, x-tracer-id, x-request-id, etc... and the actual correlation id Note, a struct, with funcs is used here, to allow callers to use whatever method / strategy is preferred to retrieve the header name, env variables, config file, db, ssm, etc... and the correlation id that will be generated if no correlation ID was provided in the request.
func (*CorrelationIDOptions) GetCorrelationID ¶
func (o *CorrelationIDOptions) GetCorrelationID() (string, error)
GetCorrelationID - returns a correlation ID Allows users of the lib to use their own correlation id generation strategy e.g. Database, different library, etc...
func (*CorrelationIDOptions) GetCorrelationIDHttpHeaderName ¶
func (o *CorrelationIDOptions) GetCorrelationIDHttpHeaderName() (string, error)