apikey

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 2, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsExemptFromRateLimits

func IsExemptFromRateLimits(r *http.Request) bool

IsExemptFromRateLimits returns true if the request's API key tier is exempt from rate limits. Enterprise and Partner tiers are exempt from wallet/IP rate limits.

func Middleware

func Middleware(cfg Config) func(http.Handler) http.Handler

Middleware validates API keys and stores tier information in request context. If no API key is provided or key is invalid, request proceeds with TierFree (default rate limits apply). If valid API key is provided, tier is stored in context for rate limit exemptions.

func ShouldBypassGlobalLimit

func ShouldBypassGlobalLimit(r *http.Request) bool

ShouldBypassGlobalLimit returns true if the request should bypass global rate limits. Only Partner tier bypasses global limits (to prevent bulk import issues).

Types

type Config

type Config struct {
	// APIKeys maps API key to tier level.
	// Example: {"pro_abc123": TierPro, "enterprise_xyz789": TierEnterprise}
	APIKeys map[string]Tier

	// Enabled controls whether API key authentication is active.
	Enabled bool
}

Config holds API key configuration.

type Tier

type Tier string

Tier represents the API key tier level.

const (
	TierFree       Tier = "free"       // Default tier with standard rate limits
	TierPro        Tier = "pro"        // Pro tier with higher limits
	TierEnterprise Tier = "enterprise" // Enterprise tier with no limits
	TierPartner    Tier = "partner"    // Trusted partner (Stripe, etc.) with no limits
)

func GetTier

func GetTier(r *http.Request) Tier

GetTier extracts the API key tier from request context. Returns TierFree if no tier is set (default).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL