content

package
v0.0.0-...-963cf5d Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2026 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("not found")

ErrNotFound is returned when the remote resource responds with HTTP 404.

Functions

func ResetOriginBackoff

func ResetOriginBackoff()

ResetOriginBackoff ends a running origin pause. Meant for tests, which share the process-wide pause.

func SetHTTPClient

func SetHTTPClient(client *http.Client) func()

SetHTTPClient overrides the package HTTP client and returns a restore function. This is primarily useful for tests that need a custom transport.

Types

type CacheManager

type CacheManager struct {
	// contains filtered or unexported fields
}

func NewCacheManager

func NewCacheManager(dir, manifestPath string, ttl int) (*CacheManager, error)

func (*CacheManager) ClearManifest

func (c *CacheManager) ClearManifest() error

func (*CacheManager) ETagFor

func (c *CacheManager) ETagFor(url string) string

ETagFor returns the cached ETag for the given URL, or an empty string if the URL is not in the manifest yet.

func (*CacheManager) Get

func (c *CacheManager) Get(url string) (string, error)

Get revalidates url against the origin (conditional GET), compiles the body as Markdown, caches the resulting HTML, and returns it.

An entry is revalidated with the origin via ETag/Last-Modified at most every revalidateInterval. When the origin fails, the cached body is served whatever its age (a stale page beats an error page); past TTL this is logged as an ERROR so an origin outage does not go unnoticed.

func (*CacheManager) GetRaw

func (c *CacheManager) GetRaw(url string) (string, error)

GetRaw revalidates url and caches the raw response body (no Markdown compilation). Use this for SML page definitions fetched from a remote repo.

func (*CacheManager) SetRevalidateInterval

func (c *CacheManager) SetRevalidateInterval(d time.Duration)

SetRevalidateInterval changes how long an entry is served without asking the origin (default revalidateInterval; 0 = revalidate on every call).

type FetchResult

type FetchResult struct {
	Body         []byte
	ETag         string
	LastModified string
	NotModified  bool
}

func Fetch

func Fetch(url, etag, lastModified string) (*FetchResult, error)

type Manifest

type Manifest struct {
	Version int                      `json:"version"`
	Entries map[string]ManifestEntry `json:"entries"`
}

type ManifestEntry

type ManifestEntry struct {
	URL          string    `json:"url"`
	ETag         string    `json:"etag"`
	LastModified string    `json:"last_modified"`
	SHA256       string    `json:"sha256"`
	CachedAt     time.Time `json:"cached_at"`
	SizeBytes    int64     `json:"size_bytes"`
}

type RateLimitError

type RateLimitError struct {
	URL        string
	RetryAfter time.Duration
}

RateLimitError is returned for HTTP 429; RetryAfter is the origin's Retry-After (0 if missing or not in seconds).

func (*RateLimitError) Error

func (e *RateLimitError) Error() string

Jump to

Keyboard shortcuts

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