Documentation
¶
Overview ¶
Package api provides an HTTP API-based data enrichment adapter with rate limiting, health checks, and circuit breaker support.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewAPIEnricher ¶
func NewAPIEnricher(config Config) (port.EnrichmentPort, error)
NewAPIEnricher creates a new API enrichment adapter with error handling Validates configuration and initializes rate limiter and error coordinator
Types ¶
type APIEnricher ¶
type APIEnricher struct {
// contains filtered or unexported fields
}
APIEnricher implements the EnrichmentPort interface using HTTP API as backend Supports single and batch enrichment with rate limiting and error handling
func (*APIEnricher) BatchEnrich ¶
func (ae *APIEnricher) BatchEnrich(ctx context.Context, keys []string, data []map[string]any) ([]map[string]any, error)
BatchEnrich fetches enrichment data for multiple keys Processes each key respecting rate limiting
func (*APIEnricher) Enrich ¶
func (ae *APIEnricher) Enrich(ctx context.Context, key string, data map[string]any) (map[string]any, error)
Enrich fetches enrichment data from API for a single key Uses coordinator for automatic retry, circuit breaking, and error handling Respects rate limiting and operation timeout
func (*APIEnricher) IsAvailable ¶
func (ae *APIEnricher) IsAvailable(ctx context.Context) bool
IsAvailable checks if API is reachable and healthy
type Config ¶
type Config struct {
Client *http.Client
BaseURL string
APIKey string
OperationTimeout time.Duration
HealthCheckPath string
RequestsPerSecond float64
}
Config holds API enricher configuration
type HealthChecker ¶
type HealthChecker struct {
// contains filtered or unexported fields
}
HealthChecker provides health check operations for API
func NewHealthChecker ¶
func NewHealthChecker(client *http.Client, timeout time.Duration, baseURL, healthCheckPath string) *HealthChecker
NewHealthChecker creates a new health checker
type RateLimiter ¶
type RateLimiter struct {
// contains filtered or unexported fields
}
RateLimiter controls the rate of API requests Uses token bucket algorithm for smooth rate limiting
func NewRateLimiter ¶
func NewRateLimiter(rps float64) *RateLimiter
NewRateLimiter creates a new rate limiter with given RPS burst is set equal to RPS for smooth bursts
func (*RateLimiter) Allow ¶
func (rl *RateLimiter) Allow() bool
Allow returns true if a token is immediately available