cdn

package
v0.9.5 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package cdn holds what every edge provider shares: the provider contract, the purge history and the per-step setup result, so callers never branch on which CDN sits in front of an app.

Index

Constants

View Source
const (
	TriggerPublish  = "publish"
	TriggerDeploy   = "deploy"
	TriggerRollback = "rollback"
)

Purge triggers, so the history says why the cache was cleared.

View Source
const (
	StatusOK      = "ok"
	StatusWarn    = "warn"
	StatusFail    = "fail"
	StatusSkipped = "skipped"
)

Step statuses, the same words the doctor checks use.

View Source
const (
	StepProvider = "provider"
	StepSSLMode  = "ssl_mode"
	StepDNS01    = "acme_dns01"
	StepClientIP = "client_address"
	StepDNSPlan  = "dns_plan"
	StepApply    = "apply"
	StepVerify   = "verify"
)

Setup step ids, in run order.

View Source
const EnvPurgeHistory = "APP_CDN_PURGE_HISTORY"

EnvPurgeHistory caps the purge records kept per app.

View Source
const ProviderCloudflare = "cloudflare"

ProviderCloudflare is the name the Cloudflare adapter reports.

View Source
const ScopeHosts = "hosts"

ScopeHosts is a purge of every URL under the app's hostnames.

Variables

This section is empty.

Functions

This section is empty.

Types

type Fake

type Fake struct {
	ID       string
	Mode     string
	PurgeErr error
	ModeErr  error
	// contains filtered or unexported fields
}

Fake is an in-memory Provider for tests and for providers not yet wired.

func (*Fake) Name

func (f *Fake) Name() string

Name implements Provider.

func (*Fake) PurgeHosts

func (f *Fake) PurgeHosts(_ context.Context, _ string, hosts []string) error

PurgeHosts records the hosts and returns PurgeErr.

func (*Fake) Purges

func (f *Fake) Purges() [][]string

Purges returns the host batches purged so far.

func (*Fake) SSLMode

func (f *Fake) SSLMode(context.Context, string) (string, error)

SSLMode returns Mode, or ModeErr.

type History

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

History keeps the newest purge records per app in memory.

func DefaultHistory

func DefaultHistory() *History

DefaultHistory is the process-wide history the API writes and reads.

func NewHistory

func NewHistory(keep int) *History

NewHistory returns a history keeping keep records per app; keep <= 0 reads the environment.

func (*History) Add

func (h *History) Add(app string, r PurgeRecord)

Add stores r for app, newest first.

func (*History) List

func (h *History) List(app string, limit int) []PurgeRecord

List returns up to limit records for app, newest first.

func (*History) SetKeep

func (h *History) SetKeep(n int)

SetKeep changes the per-app cap live; n <= 0 is ignored. Existing rows are trimmed on the next Add.

type Provider

type Provider interface {
	// Name is the stable provider id shown in status and history.
	Name() string
	// PurgeHosts clears the edge cache for every URL under each host in zone.
	PurgeHosts(ctx context.Context, zone string, hosts []string) error
	// SSLMode reads how the edge talks to the origin: off, flexible, full or strict.
	SSLMode(ctx context.Context, zone string) (string, error)
}

Provider is the edge operations Levelrail needs from a CDN.

type PurgeRecord

type PurgeRecord struct {
	At       time.Time `json:"at"`
	Trigger  string    `json:"trigger"`
	Scope    string    `json:"scope"`
	Provider string    `json:"provider"`
	Zones    []string  `json:"zones"`
	Hosts    int       `json:"hosts"`
	OK       bool      `json:"ok"`
	Error    string    `json:"error,omitempty"`
}

PurgeRecord is one edge purge attempt for an app.

type SetupResult

type SetupResult struct {
	App      string `json:"app"`
	Provider string `json:"provider"`
	DryRun   bool   `json:"dry_run"`
	Applied  bool   `json:"applied"`
	Status   string `json:"status"`
	Steps    []Step `json:"steps"`
}

SetupResult is the answer to a setup run, usable as a wizard's state.

func (*SetupResult) Summarize

func (r *SetupResult) Summarize()

Summarize sets Status to the worst step status: fail, then warn, else ok.

type Step

type Step struct {
	ID      string `json:"id"`
	Status  string `json:"status"`
	Message string `json:"message"`
	// Fix is the command that resolves a warn or fail, empty when none is needed.
	Fix string `json:"fix,omitempty"`
}

Step is one line of the setup checklist.

Jump to

Keyboard shortcuts

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