Documentation
¶
Overview ¶
Package httpstore provides the event adapter for HTTP resource fetching.
This package wraps the pure httpstore component (pkg/httpstore) with event coordination. It manages refresh timers and publishes events when content changes, allowing the reconciliation pipeline to validate new content before accepting it.
Index ¶
Constants ¶
const ( // ComponentName is the unique identifier for this component. ComponentName = "httpstore" // EventBufferSize is the size of the event subscription buffer. // Size 50: Low-volume component handling validation events (~1-2 per reconciliation). // HTTP refresh operations are timer-driven, not event-driven. EventBufferSize = 50 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Component ¶
type Component struct {
// contains filtered or unexported fields
}
Component wraps HTTPStore with event coordination.
It manages:
- Refresh timers for URLs with delay > 0
- Event publishing when content changes
- Pending content promotion/rejection based on proposal validation results
- Periodic eviction of unused cache entries
Event subscriptions:
- ProposalValidationCompletedEvent: Check if our validation, promote/reject pending
Event publications:
- ProposalValidationRequestedEvent: When refreshed content differs from accepted
- HTTPResourceAcceptedEvent: When pending content is promoted
- HTTPResourceRejectedEvent: When pending content is rejected
- ReconciliationTriggeredEvent: After successful validation promotion
func New ¶
func New(eventBus *busevents.EventBus, logger *slog.Logger, evictionMaxAge time.Duration) *Component
New creates a new HTTPStore event adapter component.
The component subscribes to the EventBus during construction (before EventBus.Start()) to ensure proper startup synchronization.
Parameters:
- eventBus: The event bus for coordination
- logger: Logger for debug messages
- evictionMaxAge: Maximum age for unused entries before eviction (0 disables eviction)
func (*Component) GetStore ¶
GetStore returns the underlying HTTPStore. This is used by the wrapper to access cached content.
func (*Component) Name ¶
Name returns the unique identifier for this component. Implements the lifecycle.Component interface.
func (*Component) RegisterURL ¶
RegisterURL registers a URL for refresh if it has a delay configured. This is called after successful initial fetch from template rendering.
func (*Component) Start ¶
Start begins the component's event loop.
This method blocks until the context is cancelled.
func (*Component) StopRefresher ¶
StopRefresher stops the refresh timer for a specific URL.
type HTTPStoreWrapper ¶
type HTTPStoreWrapper struct {
// contains filtered or unexported fields
}
HTTPStoreWrapper wraps HTTPStore for template access.
It provides the Fetch method callable from templates:
{{ http.Fetch("https://example.com/data.txt", {"delay": "60s"}) }}
{{ http.Fetch("https://api.example.com/data", {"delay": "5m"}, {"type": "bearer", "token": token}) }}
The wrapper uses an overlay to determine content retrieval behavior:
- With overlay (validation mode): Returns pending content if available
- Without overlay (production mode): Returns accepted content only
func NewHTTPStoreWrapper ¶
func NewHTTPStoreWrapper(ctx context.Context, component *Component, logger *slog.Logger, overlay stores.HTTPContentOverlay) *HTTPStoreWrapper
NewHTTPStoreWrapper creates a new HTTPStoreWrapper.
Parameters:
- ctx: Context for HTTP requests
- component: The httpstore component for store access and URL registration
- logger: Logger for debug messages
- overlay: HTTP overlay for validation mode (nil for production mode)
When overlay is provided (validation mode), the wrapper returns pending content if available for URLs in the overlay. When overlay is nil (production mode), only accepted content is returned.
func (*HTTPStoreWrapper) Fetch ¶
func (w *HTTPStoreWrapper) Fetch(args ...interface{}) (interface{}, error)
Fetch fetches content from a URL.
Template usage:
Basic fetch (no refresh):
{{ http.Fetch("https://example.com/data.txt") }}
With refresh interval:
{{ http.Fetch("https://example.com/data.txt", {"delay": "60s"}) }}
With options:
{{ http.Fetch("https://example.com/data.txt", {"delay": "5m", "timeout": "30s", "retries": 3, "critical": true}) }}
With authentication:
{{ http.Fetch("https://api.example.com/data", {"delay": "5m"}, {"type": "bearer", "token": token}) }}
{{ http.Fetch("https://api.example.com/data", {"delay": "5m"}, {"type": "basic", "username": user, "password": pass}) }}
Parameters (variadic):
- url (string, required): The HTTP(S) URL to fetch
- options (map, optional): {"delay": "60s", "timeout": "30s", "retries": 3, "critical": true}
- auth (map, optional): {"type": "bearer"|"basic"|"header", "token": "...", "username": "...", "password": "..."}
Returns:
- Content string (empty if fetch failed and not critical)
- Error if critical fetch fails