types

package
v0.0.0-...-75bc046 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UnmatchedDimensionBlock  = "block"  // Return 403 Forbidden
	UnmatchedDimensionBypass = "bypass" // Fetch from origin (default)
)

Unmatched dimension behavior constants

View Source
const (
	BypassDimensionName = "bypass"
	BypassDimensionID   = 0
)

Bypass dimension constants

View Source
const (
	CompressionNone   = "none"   // No compression
	CompressionSnappy = "snappy" // Snappy compression (default)
	CompressionLZ4    = "lz4"    // LZ4 compression
)

Compression algorithm constants

View Source
const (
	ExtSnappy = ".snappy"
	ExtLZ4    = ".lz4"
)

Compression file extension constants

View Source
const (
	LifecycleEventDOMContentLoaded  = "DOMContentLoaded"  // DOM is ready, images may still be loading
	LifecycleEventLoad              = "load"              // Page fully loaded (all resources)
	LifecycleEventNetworkIdle       = "networkIdle"       // Network has been idle for 500ms
	LifecycleEventNetworkAlmostIdle = "networkAlmostIdle" // At most 2 network connections for 500ms
)

Lifecycle event constants for wait_for field

View Source
const (
	ErrorTypeHardTimeout         = "hard_timeout"
	ErrorTypeChromeCrash         = "chrome_crash"
	ErrorTypeChromeRestartFailed = "chrome_restart_failed"
	ErrorTypePoolUnavailable     = "pool_unavailable"
)

Error type constants - Infrastructure errors

View Source
const (
	ErrorTypeSoftTimeout          = "soft_timeout"
	ErrorTypeNavigationFailed     = "navigation_failed"
	ErrorTypeNetworkError         = "network_error"
	ErrorTypeHTMLExtractionFailed = "html_extraction_failed"
	ErrorTypeStatusCaptureFailed  = "status_capture_failed"
	ErrorTypeInvalidURL           = "invalid_url"
)

Error type constants - Render errors

View Source
const (
	ErrorTypeOrigin4xx = "origin_4xx"
	ErrorTypeOrigin5xx = "origin_5xx"
)

Error type constants - Origin errors

View Source
const (
	ErrorTypeEmptyResponse    = "empty_response"
	ErrorTypeResponseTooLarge = "response_too_large"
)

Error type constants - Content errors

View Source
const (
	ExpirationStrategyServeStale = "serve_stale" // Keep serving expired cache while recaching
	ExpirationStrategyDelete     = "delete"      // Delete expired cache and force fresh render
)

Expiration strategy constants

View Source
const (
	SelectionStrategyLeastLoaded   = "least_loaded"   // Select service with lowest load percentage
	SelectionStrategyMostAvailable = "most_available" // Select service with most available tabs
)

Registry selection strategy constants

View Source
const (
	StatusClass2xx = "2xx"
	StatusClass3xx = "3xx"
	StatusClass4xx = "4xx"
	StatusClass5xx = "5xx"
)

HTTP status class constants for PageMetrics.StatusCounts map keys

View Source
const (
	ConsoleTypeError      = "error"
	ConsoleTypeWarning    = "warning"
	AnonymousSourceURL    = "<anonymous>"
	UnknownSourceLocation = "0:0"
)

Console error type constants

View Source
const (
	MaxSEOTitleLength        = 500
	MaxMetaDescriptionLength = 1000
	MaxCanonicalURLLength    = 2000
	MaxHreflangURLLength     = 2000
	MaxHeadingLength         = 500
	MaxHeadingsPerLevel      = 5
	MaxExternalDomains       = 20
)

PageSEO extraction limits - text fields

View Source
const (
	MaxJSONLDSize           = 1024 * 1024 // 1MB per JSON-LD block
	MaxJSONLDRecursionDepth = 10          // Prevent stack overflow
)

PageSEO extraction limits - performance

View Source
const (
	ResourceTypeDocument       = "Document"
	ResourceTypeStylesheet     = "Stylesheet"
	ResourceTypeImage          = "Image"
	ResourceTypeMedia          = "Media"
	ResourceTypeFont           = "Font"
	ResourceTypeScript         = "Script"
	ResourceTypeTextTrack      = "TextTrack"
	ResourceTypeXHR            = "XHR"
	ResourceTypeFetch          = "Fetch"
	ResourceTypePrefetch       = "Prefetch"
	ResourceTypeEventSource    = "EventSource"
	ResourceTypeWebSocket      = "WebSocket"
	ResourceTypeManifest       = "Manifest"
	ResourceTypeSignedExchange = "SignedExchange"
	ResourceTypePing           = "Ping"
	ResourceTypeCSPViolation   = "CSPViolationReport"
	ResourceTypePreflight      = "Preflight"
	ResourceTypeOther          = "Other"
)

Chrome resource type constants for PageMetrics.BytesByType map keys

View Source
const CompressionMinSize = 1024

CompressionMinSize is the minimum content size in bytes for compression to be applied. Files smaller than this are stored uncompressed.

View Source
const (
	NoCacheTTL = 0 // Disables caching - content always fetched fresh
)

Cache TTL constants

Variables

This section is empty.

Functions

func DetectPatternType

func DetectPatternType(pat string) (pattern.PatternType, string, bool)

DetectPatternType is a compatibility wrapper that calls pattern.DetectPatternType Deprecated: Use pattern.DetectPatternType directly

Types

type BothitRecacheConfig

type BothitRecacheConfig struct {
	Enabled  *bool     `yaml:"enabled,omitempty" json:"enabled,omitempty"`   // Enable/disable automatic recache (pointer for override detection)
	Interval *Duration `yaml:"interval,omitempty" json:"interval,omitempty"` // Duration between recaches (30m to 24h, pointer for override detection)
	MatchUA  []string  `yaml:"match_ua,omitempty" json:"match_ua,omitempty"` // Bot User-Agent patterns (exact, wildcard, regexp support, replacement semantics)

	// CompiledPatterns stores pre-compiled user agent patterns
	CompiledPatterns []*pattern.Pattern `yaml:"-" json:"-"`
}

BothitRecacheConfig defines automatic recache behavior triggered by bot hits Can be specified at global, host, or URL pattern level with deep merge semantics match_ua array uses replacement semantics (child replaces parent completely)

func (*BothitRecacheConfig) CompileMatchUAPatterns

func (c *BothitRecacheConfig) CompileMatchUAPatterns() error

CompileMatchUAPatterns pre-compiles patterns for user agent matching Uses unified pattern package for consistent behavior: - No prefix: exact match (case-sensitive) - * wildcard: matches any characters - ~ prefix: case-sensitive regexp - ~* prefix: case-insensitive regexp

func (*BothitRecacheConfig) Validate

func (c *BothitRecacheConfig) Validate() error

Validate validates bothit_recache configuration

type BypassCacheConfig

type BypassCacheConfig struct {
	// Enabled controls whether bypass responses are cached
	// nil = inherit from parent level
	// false = explicitly disable caching
	// true = explicitly enable caching
	Enabled *bool `yaml:"enabled,omitempty" json:"enabled,omitempty"`

	// TTL is the cache duration for bypass responses
	// nil = inherit from parent level
	// 0 = explicitly disable caching for this pattern
	// >0 = cache for specified duration
	TTL *Duration `yaml:"ttl,omitempty" json:"ttl,omitempty"`

	// StatusCodes lists HTTP status codes to cache
	// nil or empty = inherit from parent level
	// non-empty = override with specified codes
	// Common: [200], [200, 404], [200, 301, 302, 404]
	StatusCodes []int `yaml:"status_codes,omitempty" json:"status_codes,omitempty"`

	Expired *CacheExpiredConfig `yaml:"expired,omitempty" json:"expired,omitempty"`
}

BypassCacheConfig defines caching behavior for bypass responses Used at global, host, and pattern levels with deep merge semantics

type BypassConfig

type BypassConfig struct {
	Enabled   *bool              `yaml:"enabled,omitempty" json:"enabled,omitempty"` // Enable/disable bypass mode (pointer for override detection)
	Timeout   *Duration          `yaml:"timeout,omitempty" json:"timeout,omitempty"` // Timeout for bypass requests
	UserAgent string             `yaml:"user_agent" json:"user_agent"`
	Cache     *BypassCacheConfig `yaml:"cache,omitempty" json:"cache,omitempty"` // Bypass response caching configuration
}

BypassConfig defines bypass behavior configuration (can be global, host-level, or pattern-level)

type BypassRuleConfig

type BypassRuleConfig struct {
	Timeout   *Duration          `yaml:"timeout,omitempty" json:"timeout,omitempty"`
	UserAgent string             `yaml:"user_agent,omitempty" json:"user_agent,omitempty"`
	Cache     *BypassCacheConfig `yaml:"cache,omitempty" json:"cache,omitempty"`
}

BypassRuleConfig defines bypass overrides for URL patterns

type CacheExpiredConfig

type CacheExpiredConfig struct {
	Strategy string    `yaml:"strategy" json:"strategy"`                       // "serve_stale" | "delete"
	StaleTTL *Duration `yaml:"stale_ttl,omitempty" json:"stale_ttl,omitempty"` // Time to live for stale cache after expiration
}

CacheExpiredConfig defines behavior when cache entries expire

type CacheKey

type CacheKey struct {
	HostID      int    `json:"h"`
	DimensionID int    `json:"d"`
	URLHash     string `json:"u"`
}

CacheKey represents a unique cache identifier

func ParseCacheKey

func ParseCacheKey(s string) (*CacheKey, error)

ParseCacheKey parses a cache key string in format "cache:host_id:dimension_id:url_hash"

func (CacheKey) String

func (ck CacheKey) String() string

String returns cache key in Redis format

type CacheShardingBehaviorConfig

type CacheShardingBehaviorConfig struct {
	Enabled              *bool  `yaml:"enabled,omitempty" json:"enabled,omitempty"`                             // Enable/disable sharding (pointer for override detection)
	ReplicationFactor    *int   `yaml:"replication_factor,omitempty" json:"replication_factor,omitempty"`       // Number of EG instances to replicate cache to (pointer for override detection)
	DistributionStrategy string `yaml:"distribution_strategy,omitempty" json:"distribution_strategy,omitempty"` // hash_modulo | random | primary_only
	PushOnRender         *bool  `yaml:"push_on_render,omitempty" json:"push_on_render,omitempty"`               // Push to replicas after render (pointer for override detection)
	ReplicateOnPull      *bool  `yaml:"replicate_on_pull,omitempty" json:"replicate_on_pull,omitempty"`         // Store pulled cache locally (pointer for override detection)
}

CacheShardingBehaviorConfig contains behavioral sharding settings that can be overridden per host/pattern

type CacheShardingConfig

type CacheShardingConfig struct {
	Enabled              *bool  `yaml:"enabled,omitempty" json:"enabled,omitempty"`                             // Enable/disable sharding (pointer for override detection)
	ReplicationFactor    *int   `yaml:"replication_factor,omitempty" json:"replication_factor,omitempty"`       // Number of EG instances to replicate cache to (pointer for override detection)
	DistributionStrategy string `yaml:"distribution_strategy,omitempty" json:"distribution_strategy,omitempty"` // hash_modulo | random | primary_only
	PushOnRender         *bool  `yaml:"push_on_render,omitempty" json:"push_on_render,omitempty"`               // Push to replicas after render (pointer for override detection)
	ReplicateOnPull      *bool  `yaml:"replicate_on_pull,omitempty" json:"replicate_on_pull,omitempty"`         // Store pulled cache locally (pointer for override detection)
}

CacheShardingConfig defines cache sharding configuration for multi-EG deployments Can be specified at global and host levels (not URL pattern level)

type ClientIPConfig

type ClientIPConfig struct {
	Headers []string `yaml:"headers,omitempty" json:"headers,omitempty"`
}

ClientIPConfig defines HTTP headers for extracting the client's real IP address.

type ConsoleError

type ConsoleError struct {
	Type           string `json:"type"`            // "error" or "warning"
	SourceURL      string `json:"source_url"`      // Script URL or "<anonymous>"
	SourceLocation string `json:"source_location"` // "line:column" format or "0:0"
	Message        string `json:"message"`         // Error message text
}

ConsoleError represents a console error or warning captured during render

type Dimension

type Dimension struct {
	ID       int           `yaml:"id" json:"id"`
	Width    int           `yaml:"width" json:"width"`
	Height   int           `yaml:"height" json:"height"`
	RenderUA string        `yaml:"render_ua" json:"render_ua"`
	MatchUA  []string      `yaml:"match_ua" json:"match_ua"`
	Action   URLRuleAction `yaml:"action,omitempty" json:"action,omitempty"`

	// CompiledPatterns stores pre-compiled user agent patterns
	CompiledPatterns []*pattern.Pattern `yaml:"-" json:"-"`
}

Dimension defines viewport configuration

func (*Dimension) CompileMatchUAPatterns

func (d *Dimension) CompileMatchUAPatterns() error

CompileMatchUAPatterns pre-compiles patterns for user agent matching Uses unified pattern package for consistent behavior: - No prefix: exact match (case-sensitive) - * wildcard: matches any characters - ~ prefix: case-sensitive regexp - ~* prefix: case-insensitive regexp

func (Dimension) EffectiveAction

func (d Dimension) EffectiveAction() URLRuleAction

EffectiveAction returns the dimension's action, defaulting to ActionRender

type DomainStats

type DomainStats struct {
	Requests   int     `json:"requests"`
	Bytes      int64   `json:"bytes"`
	Failed     int     `json:"failed"`
	Blocked    int     `json:"blocked"`
	AvgLatency float64 `json:"avg_latency"` // seconds, excludes failed requests
}

DomainStats contains per-domain network statistics.

type Duration

type Duration time.Duration

Duration wraps time.Duration with extended YAML parsing support for days and weeks

func (Duration) MarshalJSON

func (d Duration) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler for Duration.

func (Duration) MarshalYAML

func (d Duration) MarshalYAML() (interface{}, error)

MarshalYAML implements yaml.Marshaler

func (Duration) String

func (d Duration) String() string

String implements fmt.Stringer for Duration

func (Duration) ToDuration

func (d Duration) ToDuration() time.Duration

ToDuration converts types.Duration to time.Duration

func (*Duration) UnmarshalJSON

func (d *Duration) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler for Duration. Accepts both numbers (nanoseconds, backward-compatible) and strings ("15s", "24h", "30d", "2w").

func (*Duration) UnmarshalYAML

func (d *Duration) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements yaml.Unmarshaler for extended duration formats

type EGInfo

type EGInfo struct {
	EgID            string    `json:"eg_id"`
	Address         string    `json:"address"`
	LastHeartbeat   time.Time `json:"last_heartbeat"`
	ShardingEnabled bool      `json:"sharding_enabled"`
}

EGInfo represents information about an Edge Gateway instance in the registry

type HeadersConfig

type HeadersConfig struct {
	// SafeRequest replaces parent's request headers list
	SafeRequest []string `yaml:"safe_request,omitempty" json:"safe_request,omitempty"`
	// SafeRequestAdd adds to parent's request headers list
	SafeRequestAdd []string `yaml:"safe_request_add,omitempty" json:"safe_request_add,omitempty"`
	// SafeResponse replaces parent's response headers list
	SafeResponse []string `yaml:"safe_response,omitempty" json:"safe_response,omitempty"`
	// SafeResponseAdd adds to parent's response headers list
	SafeResponseAdd []string `yaml:"safe_response_add,omitempty" json:"safe_response_add,omitempty"`
}

HeadersConfig defines safe request and response headers configuration. Supports both replacement (safe_*) and additive (safe_*_add) directives. At each config level, only ONE of safe_request/safe_request_add can be used (same for response).

type Host

type Host struct {
	ID                 int                          `yaml:"id" json:"id"`
	Domain             string                       `yaml:"-" json:"-"`
	Domains            []string                     `yaml:"-" json:"domain"`
	RenderKey          string                       `yaml:"render_key" json:"render_key"`
	Enabled            bool                         `yaml:"enabled" json:"enabled"`
	Dimensions         map[string]Dimension         `yaml:"dimensions" json:"dimensions"`
	UnmatchedDimension string                       `yaml:"unmatched_dimension" json:"unmatched_dimension"`
	Render             RenderConfig                 `yaml:"render" json:"render"`
	Bypass             *BypassConfig                `yaml:"bypass,omitempty" json:"bypass,omitempty"`                   // Host-level bypass override (optional, pointer for override detection)
	TrackingParams     *TrackingParamsConfig        `yaml:"tracking_params,omitempty" json:"tracking_params,omitempty"` // Host-level tracking params override
	CacheSharding      *CacheShardingBehaviorConfig `yaml:"cache_sharding,omitempty" json:"cache_sharding,omitempty"`   // Host-level cache sharding override (behavioral settings only)
	BothitRecache      *BothitRecacheConfig         `yaml:"bothit_recache,omitempty" json:"bothit_recache,omitempty"`   // Host-level bot hit recache override
	Headers            *HeadersConfig               `yaml:"headers,omitempty" json:"headers,omitempty"`                 // Host-level headers override
	ClientIP           *ClientIPConfig              `yaml:"client_ip,omitempty" json:"client_ip,omitempty"`             // Host-level client IP override
	URLRules           []URLRule                    `yaml:"url_rules,omitempty" json:"url_rules,omitempty"`             // URL pattern rules
}

Host represents a domain configuration

func (Host) MarshalYAML

func (h Host) MarshalYAML() (interface{}, error)

MarshalYAML implements yaml.Marshaler for Host. Outputs Domains as "domain" field (single string if one domain, array if multiple).

func (*Host) UnmarshalJSON

func (h *Host) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler for Host. Handles both string and array formats for domain field and strips trailing dots.

func (*Host) UnmarshalYAML

func (h *Host) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements custom YAML unmarshaling for Host. Handles both string and array formats for domain field and strips trailing dots (FQDN normalization).

type HreflangEntry

type HreflangEntry struct {
	Lang string `json:"lang"` // Language/region code (e.g., "en-US", "x-default")
	URL  string `json:"url"`  // Alternate URL (resolved to absolute)
}

HreflangEntry represents a single hreflang alternate link

type IndexStatus

type IndexStatus int

IndexStatus represents the indexability status of a rendered page

const (
	IndexStatusIndexable     IndexStatus = 1 // Page can be indexed
	IndexStatusNon200        IndexStatus = 2 // Non-200 status code
	IndexStatusBlockedByMeta IndexStatus = 3 // Blocked by robots/googlebot meta tag
	IndexStatusNonCanonical  IndexStatus = 4 // Canonical URL points elsewhere
)

IndexStatus constants for page indexability

type InvalidateAPIData

type InvalidateAPIData struct {
	HostID             int `json:"host_id"`
	URLsCount          int `json:"urls_count"`
	DimensionIDsCount  int `json:"dimension_ids_count"`
	EntriesInvalidated int `json:"entries_invalidated"`
}

InvalidateAPIData is the data payload for POST /internal/cache/invalidate response

type InvalidateAPIRequest

type InvalidateAPIRequest struct {
	HostID       int      `json:"host_id"`
	URLs         []string `json:"urls"`
	DimensionIDs []int    `json:"dimension_ids"` // Optional, empty = all
}

InvalidateAPIRequest is the request body for POST /internal/cache/invalidate

type InvalidateAllAPIData

type InvalidateAllAPIData struct {
	HostID             int `json:"host_id"`
	DimensionIDsCount  int `json:"dimension_ids_count"`
	EntriesInvalidated int `json:"entries_invalidated"`
}

InvalidateAllAPIData is the data payload for POST /internal/cache/invalidate-all response

type InvalidateAllAPIRequest

type InvalidateAllAPIRequest struct {
	HostID       int   `json:"host_id"`
	DimensionIDs []int `json:"dimension_ids"` // Optional, empty = all
}

InvalidateAllAPIRequest is the request body for POST /internal/cache/invalidate-all

type LifecycleEvent

type LifecycleEvent struct {
	Name string  `json:"name"` // event name (e.g., "DOMContentLoaded", "load", "networkIdle")
	Time float64 `json:"time"` // seconds from navigation start
}

LifecycleEvent represents a single page lifecycle event

type PageMetrics

type PageMetrics struct {
	StatusCode      int              `json:"status_code"`
	FinalURL        string           `json:"final_url"`
	LifecycleEvents []LifecycleEvent `json:"lifecycle_events,omitempty"`
	TimedOut        bool             `json:"timed_out"`
	ConsoleMessages []ConsoleError   `json:"console_messages,omitempty"`

	// Network metrics
	TotalRequests      int              `json:"total_requests"`
	TotalBytes         int64            `json:"total_bytes"`
	BytesByType        map[string]int64 `json:"bytes_by_type,omitempty"`
	RequestsByType     map[string]int64 `json:"requests_by_type,omitempty"`
	StatusCounts       map[string]int64 `json:"status_counts,omitempty"`
	SameOriginRequests int              `json:"same_origin_requests"`
	SameOriginBytes    int64            `json:"same_origin_bytes"`
	ThirdPartyRequests int              `json:"third_party_requests"`
	ThirdPartyBytes    int64            `json:"third_party_bytes"`
	ThirdPartyDomains  int              `json:"third_party_domains"`
	BlockedCount       int              `json:"blocked_count"`
	FailedCount        int              `json:"failed_count"`
	TimeToFirstRequest float64          `json:"time_to_first_request"`
	TimeToLastResponse float64          `json:"time_to_last_response"`

	// Per-domain statistics (max 100 domains, sorted by request count)
	// Key is hostname without port (e.g., "example.com", "api.reviews.io")
	DomainStats map[string]*DomainStats `json:"domain_stats,omitempty"`

	// Render configuration used (for analytics)
	WaitForEvent   string  `json:"wait_for_event,omitempty"`  // target lifecycle event
	ExtraWait      float64 `json:"extra_wait,omitempty"`      // configured extra wait (seconds)
	Timeout        float64 `json:"timeout,omitempty"`         // configured timeout (seconds)
	ViewportWidth  int     `json:"viewport_width,omitempty"`  // viewport width
	ViewportHeight int     `json:"viewport_height,omitempty"` // viewport height
}

PageMetrics contains metrics collected during page rendering

type PageSEO

type PageSEO struct {
	// Basic metadata
	Title       string      `json:"title,omitempty"`
	IndexStatus IndexStatus `json:"index_status,omitempty"`

	// Meta tags
	MetaDescription string   `json:"meta_description,omitempty"`
	CanonicalURL    string   `json:"canonical_url,omitempty"`
	MetaRobots      []string `json:"meta_robots,omitempty"`

	// Headings (first 5 of each level, max 500 chars each)
	H1s []string `json:"h1s,omitempty"`
	H2s []string `json:"h2s,omitempty"`
	H3s []string `json:"h3s,omitempty"`

	// Links analysis
	LinksTotal            int            `json:"links_total,omitempty"`
	LinksInternal         int            `json:"links_internal,omitempty"`
	LinksExternal         int            `json:"links_external,omitempty"`
	LinksNofollow         int            `json:"links_nofollow,omitempty"`
	LinksNofollowInternal int            `json:"links_nofollow_internal,omitempty"`
	LinksNofollowExternal int            `json:"links_nofollow_external,omitempty"`
	ExternalDomains       map[string]int `json:"external_domains,omitempty"`

	// Images analysis
	ImagesTotal      int `json:"images_total,omitempty"`
	ImagesInternal   int `json:"images_internal,omitempty"`
	ImagesExternal   int `json:"images_external,omitempty"`
	ImagesWithAlt    int `json:"images_with_alt,omitempty"`
	ImagesWithoutAlt int `json:"images_without_alt,omitempty"`

	// Content analysis
	WordCount   int      `json:"word_count,omitempty"`
	PageMinHash []uint64 `json:"page_minhash,omitempty"`

	// International SEO
	Hreflang     []HreflangEntry `json:"hreflang,omitempty"`
	HreflangSelf string          `json:"hreflang_self,omitempty"`

	// Structured data
	StructuredDataTypes []string `json:"structured_data_types,omitempty"`
}

PageSEO contains SEO-relevant metadata extracted from rendered HTML

type PatternMetadata

type PatternMetadata struct {
	PatternType           pattern.PatternType
	CompiledRegexp        *regexp.Regexp
	RegexpCaseInsensitive bool
}

PatternMetadata contains pre-compiled pattern matching data (deprecated, use pattern.Pattern)

type RecacheAPIData

type RecacheAPIData struct {
	HostID            int    `json:"host_id"`
	URLsCount         int    `json:"urls_count"`
	DimensionIDsCount int    `json:"dimension_ids_count"`
	EntriesEnqueued   int    `json:"entries_enqueued"`
	Priority          string `json:"priority"`
}

RecacheAPIData is the data payload for POST /internal/cache/recache response

type RecacheAPIRequest

type RecacheAPIRequest struct {
	HostID       int      `json:"host_id"`       // Host identifier from hosts.yaml
	URLs         []string `json:"urls"`          // URLs to recache (1-10000)
	DimensionIDs []int    `json:"dimension_ids"` // Dimension IDs (optional, empty = all)
	Priority     string   `json:"priority"`      // "high" or "normal"
}

RecacheAPIRequest is the request body for POST /internal/cache/recache

type RecacheMember

type RecacheMember struct {
	URL         string `json:"url"`          // Normalized URL
	DimensionID int    `json:"dimension_id"` // Integer dimension ID (1, 2, 3...)
}

RecacheMember represents a ZSET member for recache queues

type RenderCacheConfig

type RenderCacheConfig struct {
	TTL         *Duration           `yaml:"ttl,omitempty" json:"ttl,omitempty"`                   // Optional TTL override (nil = use global, &0 = no cache)
	StatusCodes []int               `yaml:"status_codes,omitempty" json:"status_codes,omitempty"` // HTTP status codes to cache (default: [200, 301, 302, 307, 308, 404])
	Expired     *CacheExpiredConfig `yaml:"expired,omitempty" json:"expired,omitempty"`           // Optional expiration behavior override
}

RenderCacheConfig defines caching behavior for render action

type RenderCacheOverride

type RenderCacheOverride struct {
	TTL         *Duration           `yaml:"ttl,omitempty" json:"ttl,omitempty"`                   // Override TTL
	StatusCodes []int               `yaml:"status_codes,omitempty" json:"status_codes,omitempty"` // Override cacheable status codes
	Expired     *CacheExpiredConfig `yaml:"expired,omitempty" json:"expired,omitempty"`           // Override expiration behavior
}

RenderCacheOverride defines cache overrides for URL patterns with action="render"

type RenderConfig

type RenderConfig struct {
	Timeout              Duration           `yaml:"timeout" json:"timeout"`
	Events               RenderEvents       `yaml:"events" json:"events"`
	Cache                *RenderCacheConfig `yaml:"cache,omitempty" json:"cache,omitempty"`                                   // Cache configuration for render action
	BlockedResourceTypes []string           `yaml:"blocked_resource_types,omitempty" json:"blocked_resource_types,omitempty"` // Resource types to block during rendering
	BlockedPatterns      []string           `yaml:"blocked_patterns,omitempty" json:"blocked_patterns,omitempty"`             // URL patterns to block (domains/paths)
	StripScripts         *bool              `yaml:"strip_scripts,omitempty" json:"strip_scripts,omitempty"`
}

RenderConfig defines rendering behavior

type RenderEvents

type RenderEvents struct {
	WaitFor        string    `yaml:"wait_for" json:"wait_for"`
	AdditionalWait *Duration `yaml:"additional_wait,omitempty" json:"additional_wait,omitempty"`
}

RenderEvents defines page ready detection

type RenderRequest

type RenderRequest struct {
	// Request identification
	RequestID string `json:"request_id"`
	URL       string `json:"url"`
	TabID     int    `json:"tab_id"` // Reserved Chrome tab ID from Lua script

	// Rendering configuration
	ViewportWidth  int    `json:"viewport_width"`
	ViewportHeight int    `json:"viewport_height"`
	UserAgent      string `json:"user_agent"`

	// Timing configuration
	Timeout   time.Duration `json:"timeout"`    // render timeout duration
	WaitFor   string        `json:"wait_for"`   // lifecycle event: "DOMContentLoaded", "load", "networkIdle", "networkAlmostIdle"
	ExtraWait time.Duration `json:"extra_wait"` // additional wait duration after event

	// Request blocking configuration
	BlockedPatterns      []string `json:"blocked_patterns,omitempty"`       // URL patterns to block (domains/paths)
	BlockedResourceTypes []string `json:"blocked_resource_types,omitempty"` // Resource types to block (Image, Media, Font, etc.)

	// HAR generation
	IncludeHAR bool `json:"include_har,omitempty"` // Generate HAR data for debugging

	// Client request headers forwarding (same-origin only)
	Headers map[string][]string `json:"headers,omitempty"` // Client request headers to forward to origin

}

RenderRequest represents a page render request (EG→RS communication)

type RenderResponse

type RenderResponse struct {
	RequestID  string              `json:"request_id"`
	Success    bool                `json:"success"`
	HTML       string              `json:"html,omitempty"`
	Error      string              `json:"error,omitempty"`
	ErrorType  string              `json:"error_type,omitempty"` // Structured error category (e.g., "soft_timeout", "navigation_failed")
	RenderTime time.Duration       `json:"render_time"`          // render duration
	HTMLSize   int                 `json:"html_size"`            // bytes
	Timestamp  time.Time           `json:"timestamp"`
	ChromeID   string              `json:"chrome_id"`
	Metrics    PageMetrics         `json:"metrics,omitempty"` // Page rendering metrics
	Headers    map[string][]string `json:"headers,omitempty"` // HTTP response headers from rendered page
	HAR        json.RawMessage     `json:"har,omitempty"`     // HAR data for debugging (JSON bytes)
}

RenderResponse represents a render result (unified for RS→EG and Chrome→RS)

type RenderResponseMetadata

type RenderResponseMetadata struct {
	RequestID  string              `json:"request_id"`
	Success    bool                `json:"success"`
	Error      string              `json:"error,omitempty"`
	ErrorType  string              `json:"error_type,omitempty"` // Structured error category
	RenderTime time.Duration       `json:"render_time"`          // render duration
	HTMLSize   int                 `json:"html_size"`            // bytes
	Timestamp  time.Time           `json:"timestamp"`
	ChromeID   string              `json:"chrome_id"`
	Metrics    PageMetrics         `json:"metrics,omitempty"` // Page rendering metrics
	Headers    map[string][]string `json:"headers,omitempty"` // HTTP response headers from rendered page
	HAR        json.RawMessage     `json:"har,omitempty"`     // HAR data for debugging (JSON bytes)
}

RenderResponseMetadata contains render metadata without HTML content Used for efficient binary protocol (metadata + raw HTML)

type RenderRuleConfig

type RenderRuleConfig struct {
	Timeout              *Duration            `yaml:"timeout,omitempty" json:"timeout,omitempty"`                               // Override render timeout
	Dimension            string               `yaml:"dimension,omitempty" json:"dimension,omitempty"`                           // Force specific dimension
	Events               *RenderEvents        `yaml:"events,omitempty" json:"events,omitempty"`                                 // Override events
	Cache                *RenderCacheOverride `yaml:"cache,omitempty" json:"cache,omitempty"`                                   // Override cache behavior
	BlockedPatterns      []string             `yaml:"blocked_patterns,omitempty" json:"blocked_patterns,omitempty"`             // Override blocked URL patterns
	BlockedResourceTypes []string             `yaml:"blocked_resource_types,omitempty" json:"blocked_resource_types,omitempty"` // Override blocked resource types
	StripScripts         *bool                `yaml:"strip_scripts,omitempty" json:"strip_scripts,omitempty"`
}

RenderRuleConfig defines render overrides for URL patterns

type RenderServer

type RenderServer struct {
	ID       string    `json:"id"`
	Address  string    `json:"address"`
	Status   string    `json:"status"`
	Weight   int       `json:"weight"`
	MaxQueue int       `json:"max_queue"`
	LastSeen time.Time `json:"last_seen"`
}

RenderServer represents a render service instance

type StatusRuleConfig

type StatusRuleConfig struct {
	Code    *int              `yaml:"code,omitempty" json:"code,omitempty"`       // HTTP status code (required for generic 'status' action, inferred for aliases)
	Reason  string            `yaml:"reason,omitempty" json:"reason,omitempty"`   // Optional reason for response body (4xx/5xx only)
	Headers map[string]string `yaml:"headers,omitempty" json:"headers,omitempty"` // Custom headers (Location required for 3xx)
}

StatusRuleConfig defines status action configuration for HTTP status responses (3xx, 4xx, 5xx)

type TrackingParamsConfig

type TrackingParamsConfig struct {
	Strip     *bool    `yaml:"strip,omitempty" json:"strip,omitempty"`           // Master enable/disable switch (nil = inherit, true = strip, false = no stripping)
	Params    []string `yaml:"params,omitempty" json:"params,omitempty"`         // Replace all params (defaults + parents) with these patterns
	ParamsAdd []string `yaml:"params_add,omitempty" json:"params_add,omitempty"` // Extend parent params with these patterns
}

TrackingParamsConfig defines tracking parameter stripping configuration Can be specified at global, host, or URL pattern level with deep merge semantics

type URLRule

type URLRule struct {
	Match  interface{}   `yaml:"match" json:"match"`   // string or []string - URL pattern(s)
	Action URLRuleAction `yaml:"action" json:"action"` // "render" | "bypass" | "block" | "status_403" | "status_404" | "status_410" | "status"

	// Query parameter matching (optional, all conditions must match - AND logic)
	MatchQuery map[string]interface{} `yaml:"match_query,omitempty" json:"match_query,omitempty"`

	// Render overrides (only for action="render")
	Render *RenderRuleConfig `yaml:"render,omitempty" json:"render,omitempty"`

	// Bypass overrides (only for action="bypass")
	Bypass *BypassRuleConfig `yaml:"bypass,omitempty" json:"bypass,omitempty"`

	// Status configuration (only for status actions: block, status_403, status_404, status_410, status)
	Status *StatusRuleConfig `yaml:"status,omitempty" json:"status,omitempty"`

	// Tracking parameter stripping configuration (pattern-level override)
	TrackingParams *TrackingParamsConfig `yaml:"tracking_params,omitempty" json:"tracking_params,omitempty"`

	// Cache sharding configuration (pattern-level override)
	CacheSharding *CacheShardingBehaviorConfig `yaml:"cache_sharding,omitempty" json:"cache_sharding,omitempty"`

	// Bot hit automatic recache configuration (pattern-level override)
	BothitRecache *BothitRecacheConfig `yaml:"bothit_recache,omitempty" json:"bothit_recache,omitempty"`

	// Headers configuration (pattern-level override)
	Headers *HeadersConfig `yaml:"headers,omitempty" json:"headers,omitempty"`

	// QueryParamMetadata stores pre-compiled query parameter patterns
	// Key is the parameter name, value is array of patterns (for OR logic)
	QueryParamMetadata map[string][]*pattern.Pattern `yaml:"-" json:"-"`
	// contains filtered or unexported fields
}

URLRule defines behavior for URLs matching specific patterns any added config fields should be processed in the config.expandMultiPatternRules

func (*URLRule) CompilePatterns

func (r *URLRule) CompilePatterns() error

CompilePatterns compiles patterns for programmatically-created URLRule instances This is a convenience method for testing and dynamic rule creation

func (*URLRule) GetCompiledPattern

func (r *URLRule) GetCompiledPattern(index int) *pattern.Pattern

GetCompiledPattern returns the compiled pattern for a given index

func (*URLRule) GetMatchPatterns

func (r *URLRule) GetMatchPatterns() []string

GetMatchPatterns returns URL patterns as string slice (zero-allocation after unmarshaling)

func (*URLRule) UnmarshalYAML

func (r *URLRule) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements custom YAML unmarshaling to pre-compute match patterns

type URLRuleAction

type URLRuleAction string

URLRuleAction defines the action type for URL patterns

const (
	ActionRender    URLRuleAction = "render"     // Render with Chrome, cache result
	ActionBypass    URLRuleAction = "bypass"     // Fetch directly from origin, no rendering
	ActionBlock     URLRuleAction = "block"      // Reject request with 403 (alias for status_403)
	ActionStatus403 URLRuleAction = "status_403" // Return 403 Forbidden (explicit)
	ActionStatus404 URLRuleAction = "status_404" // Return 404 Not Found
	ActionStatus410 URLRuleAction = "status_410" // Return 410 Gone
	ActionStatus    URLRuleAction = "status"     // Generic status with configurable code
)

Action constants

func (URLRuleAction) IsStatusAction

func (a URLRuleAction) IsStatusAction() bool

IsStatusAction returns true if the action is any status-related action

func (URLRuleAction) IsValid

func (a URLRuleAction) IsValid() bool

IsValid checks if the action is valid

func (URLRuleAction) NormalizeBlockAction

func (a URLRuleAction) NormalizeBlockAction() URLRuleAction

NormalizeBlockAction returns ActionStatus403 for both "block" and "block_403" This ensures consistent handling while maintaining backward compatibility

Jump to

Keyboard shortcuts

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