httpstore

package
v0.1.0-alpha.9 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

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

View Source
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 validation results
  • Periodic eviction of unused cache entries

Event subscriptions:

  • ValidationCompletedEvent: Promote pending content to accepted
  • ValidationFailedEvent: Reject pending content

Event publications:

  • HTTPResourceUpdatedEvent: When refreshed content differs from accepted
  • HTTPResourceAcceptedEvent: When pending content is promoted
  • HTTPResourceRejectedEvent: When pending content is rejected

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

func (c *Component) GetStore() *httpstore.HTTPStore

GetStore returns the underlying HTTPStore. This is used by the wrapper to access cached content.

func (*Component) Name

func (c *Component) Name() string

Name returns the unique identifier for this component. Implements the lifecycle.Component interface.

func (*Component) RegisterURL

func (c *Component) RegisterURL(url string)

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

func (c *Component) Start(ctx context.Context) error

Start begins the component's event loop.

This method blocks until the context is cancelled.

func (*Component) StopRefresher

func (c *Component) StopRefresher(url string)

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}) }}

During validation renders, it returns pending content if available. During production renders, it returns accepted content only.

func NewHTTPStoreWrapper

func NewHTTPStoreWrapper(ctx context.Context, component *Component, logger *slog.Logger, isValidation bool) *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
  • isValidation: If true, return pending content; if false, return accepted only

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

Jump to

Keyboard shortcuts

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