Versions in this module Expand all Collapse all v0 v0.1.0 Jul 23, 2026 Changes in this version + const DefaultBaseURL + const DefaultTimeout + const MaxBodyCharacters + const Version + var DefaultErrorMessages = map[ErrorCode]string + var ErrAPI = errors.New("reqkey API error") + var ErrAuthentication = errors.New("reqkey authentication error") + var ErrConfiguration = errors.New("reqkey configuration error") + var ErrTimeout = errors.New("reqkey timeout") + var ErrTransport = errors.New("reqkey transport error") + func ContextWithOutcome(ctx context.Context, outcome *AuthorizationOutcome) context.Context + func MustHTTPMiddleware(options MiddlewareOptions) func(http.Handler) http.Handler + func NewHTTPMiddleware(options MiddlewareOptions) (func(http.Handler) http.Handler, error) + func Ptr[T any](v T) *T + func ValidationErrorFromContext(ctx context.Context) (error, bool) + type APIError struct + Body map[string]any + Message string + StatusCode int + func (e *APIError) Error() string + func (e *APIError) Unwrap() error + type AuthenticationError struct + func (e *AuthenticationError) Unwrap() error + type AuthorizationKind string + const AuthorizationAllow + const AuthorizationDeny + const AuthorizationSkip + type AuthorizationOutcome struct + Decision *VerificationResult + Denial *DenialResponse + Kind AuthorizationKind + ResponseHeaders http.Header + State *AuthorizationState + ValidationError error + type AuthorizationState struct + ConsumerKey string + Decision *VerificationResult + HandlerStartedAt time.Time + Request *MiddlewareRequest + RequestStartedAt time.Time + type Client struct + func NewClient(options ClientOptions) (*Client, error) + func NewClientFromEnv(options ClientOptions) (*Client, error) + func (c *Client) Ingest(ctx context.Context, event IngestEvent) error + func (c *Client) Verify(ctx context.Context, key string, options VerifyOptions) (*VerificationResult, error) + type ClientAPI interface + Ingest func(context.Context, IngestEvent) error + Verify func(context.Context, string, VerifyOptions) (*VerificationResult, error) + type ClientIPResolver = StringResolver + type ClientOptions struct + BaseURL string + HTTPClient *http.Client + ProjectKey string + RootKey string + Timeout time.Duration + type ConfigurationError struct + Message string + func (e *ConfigurationError) Error() string + func (e *ConfigurationError) Unwrap() error + type ConsumerKeyResolver = StringResolver + type ConsumerNameResolver = StringResolver + type CreditsResolver func(context.Context, *MiddlewareRequest) (int, error) + type DenialResponse struct + Code ErrorCode + Headers http.Header + Message string + StatusCode int + func (d *DenialResponse) Body() map[string]string + type ErrorCode string + const ContextDecisionKey + const ContextErrorKey + const ContextRequestIDKey + const ErrorAccessDenied + const ErrorInsufficientCredits + const ErrorInvalidAPIKey + const ErrorMissingAPIKey + const ErrorRateLimited + const ErrorReqKeyUnavailable + type FailureMode string + const FailureClosed + const FailureOpen + type IngestEvent struct + APIID string + APIKey string + ClientIP string + ConsumerID string + ConsumerName string + Endpoint string + LatencyMS *int64 + Method string + Path string + QueryParams map[string]any + RequestBody string + RequestHeaders map[string]string + RequestID string + ResponseBody string + ResponseHeaders map[string]string + StatusCode *int + Timestamp string + UserAgent string + UserID string + type KeyLocation string + const KeyInCookie + const KeyInHeader + const KeyInQuery + type KeyScheme string + const KeyBearer + const KeyRaw + type MiddlewareErrorEvent struct + Err error + Method string + Operation string + Path string + RequestID string + StatusCode int + func (e MiddlewareErrorEvent) Message() string + type MiddlewareErrorHandler func(context.Context, MiddlewareErrorEvent) + type MiddlewareMode string + const ModeBoth + const ModeIngest + const ModeValidate + type MiddlewareOptions struct + APIID string + BaseURL string + CaptureClientIP bool + CaptureQueryParams bool + CaptureRequestHeaders bool + CaptureResponseBody bool + CaptureResponseHeaders bool + CaptureUserAgent *bool + Client ClientAPI + ClientIPResolver ClientIPResolver + ConsumerNameResolver ConsumerNameResolver + Credits *int + CreditsResolver CreditsResolver + Enabled *bool + ErrorMessages map[ErrorCode]string + ExcludePaths []string + ExcludedHeaders []string + FailureMode FailureMode + GetConsumerKey ConsumerKeyResolver + HTTPClient *http.Client + IngestDeniedRequests *bool + KeyLocation KeyLocation + KeyName string + KeyScheme KeyScheme + Mode MiddlewareMode + OnError MiddlewareErrorHandler + PathResolver PathResolver + ProjectKey string + RequestIDResolver RequestIDResolver + RootKey string + ShouldProtect ProtectionResolver + SkipMethods []string + Timeout time.Duration + type MiddlewareRequest struct + ClientIP string + Cookies map[string]string + Headers http.Header + Method string + Path string + Raw any + URL *url.URL + func NewHTTPRequest(request *http.Request) *MiddlewareRequest + type MiddlewareResponse struct + Body string + Headers http.Header + Latency time.Duration + StatusCode int + type PathResolver = StringResolver + type ProtectionResolver func(context.Context, *MiddlewareRequest) (bool, error) + type RequestIDResolver = StringResolver + type Runtime struct + func NewRuntime(options MiddlewareOptions) (*Runtime, error) + func (r *Runtime) Authorize(ctx context.Context, request *MiddlewareRequest) (*AuthorizationOutcome, error) + func (r *Runtime) CapturesResponseBody() bool + func (r *Runtime) Mode() MiddlewareMode + func (r *Runtime) Record(ctx context.Context, state *AuthorizationState, response MiddlewareResponse) + type StringResolver func(context.Context, *MiddlewareRequest) (string, error) + type TimeoutError struct + Cause error + Operation string + func (e *TimeoutError) Error() string + func (e *TimeoutError) Unwrap() error + type TransportError struct + Cause error + Message string + func (e *TransportError) Error() string + func (e *TransportError) Unwrap() error + type VerificationReason string + const ReasonDenied + const ReasonForbidden + const ReasonInsufficientCredits + const ReasonInvalidKey + const ReasonRateLimited + const ReasonValid + type VerificationResult struct + APIID string + APIName string + AllowedAPIs []string + CreditsLimit *int64 + CreditsRemaining *int64 + Message string + RateLimit map[string]any + Raw map[string]any + Reason VerificationReason + RequestID string + Resource string + RetryAfter *float64 + StatusCode int + Valid bool + func DecisionFromContext(ctx context.Context) (*VerificationResult, bool) + func (r VerificationResult) Allowed() bool + type VerifyOptions struct + APIID string + Credits *int + Resource string