themehost

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package themehost validates and runs the prebuilt theme artifacts a site is served from.

Index

Constants

View Source
const ActiveKey = "theme.active"

ActiveKey is the setting naming the theme the public site is served through.

View Source
const MaxEntries = 10_000

MaxEntries is how many files an archive may carry.

View Source
const MaxSize = 64 << 20

MaxSize is the largest a theme directory may be.

View Source
const PreviousKey = "theme.previous"

PreviousKey is the setting naming the theme a rollback returns to.

Variables

View Source
var ErrGaveUp = errors.New("themehost: the theme did not start")

ErrGaveUp reports a theme the supervisor stopped trying to start.

View Source
var ErrNotInstalled = errors.New("themehost: theme not installed")

ErrNotInstalled reports that no theme is installed under the name.

Functions

This section is empty.

Types

type Holder added in v0.2.0

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

Holder is the theme the public site is served through, replaceable while serving.

func NewHolder added in v0.2.0

func NewHolder() *Holder

NewHolder returns a Holder serving nothing.

func (*Holder) Healthy added in v0.2.0

func (h *Holder) Healthy() bool

Healthy reports whether the held theme is serving.

func (*Holder) Serving added in v0.2.0

func (h *Holder) Serving() (string, bool)

Serving returns the theme answering the public site, and whether it is answering.

func (*Holder) Swap added in v0.2.0

func (h *Holder) Swap(next *Supervisor) *Supervisor

Swap holds next instead, returning the supervisor it held.

func (*Holder) Target added in v0.2.0

func (h *Holder) Target() string

Target returns the address the held theme serves on, empty while none does.

type Installed added in v0.2.0

type Installed struct {
	// Name is the directory the theme is installed under.
	Name string
	// Version is what the manifest declares, empty when the theme will not load.
	Version string
	// Broken is why the theme will not load, empty when it loads.
	Broken string
	// Active reports whether this theme is the operator's current choice.
	Active bool
	// Serving reports whether the public site is answered by this theme right now.
	Serving bool
}

Installed describes one theme sitting in the library.

type Library added in v0.2.0

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

Library is the managed themes directory the admin lists and installs into.

func NewLibrary added in v0.2.0

func NewLibrary(dir string) *Library

NewLibrary returns the library over a managed themes directory.

func (*Library) Dir added in v0.2.0

func (l *Library) Dir() string

Dir returns the directory the library manages.

func (*Library) Install added in v0.2.0

func (l *Library) Install(name string, archive io.ReaderAt, size int64) error

Install unpacks archive as the named theme, replacing it only once it validates.

func (*Library) List added in v0.2.0

func (l *Library) List() ([]Installed, error)

List returns the installed themes in name order, reporting those that will not load.

type Manager added in v0.2.0

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

Manager installs, lists and activates the themes the public site is served through.

func NewManager added in v0.2.0

func NewManager(cfg ManagerConfig) *Manager

NewManager returns a manager over a library, holding no theme until one is activated.

func (*Manager) Activate added in v0.2.0

func (m *Manager) Activate(ctx context.Context, name string) error

Activate serves the public site through the named theme, keeping the old one until it is ready.

func (*Manager) Boot added in v0.2.0

func (m *Manager) Boot(ctx context.Context) error

Boot serves the public site through the chosen theme, staying up when a stored theme will not load.

func (*Manager) Close added in v0.2.0

func (m *Manager) Close()

Close stops the theme the manager is serving through and every theme it retired.

func (*Manager) Deactivate added in v0.2.0

func (m *Manager) Deactivate(ctx context.Context) error

Deactivate returns the public site to the built-in renderer.

func (*Manager) Holder added in v0.2.0

func (m *Manager) Holder() *Holder

Holder returns the theme the public site is served through.

func (*Manager) Install added in v0.2.0

func (m *Manager) Install(ctx context.Context, name string, archive io.ReaderAt, size int64) error

Install unpacks the archive as the named theme, refusing to replace the active one.

func (*Manager) List added in v0.2.0

func (m *Manager) List(ctx context.Context) ([]Installed, error)

List returns the installed themes, marking the chosen one and the one serving.

func (*Manager) Previous added in v0.2.0

func (m *Manager) Previous(ctx context.Context) (string, bool, error)

Previous returns the choice a rollback would return to, and whether one is offered.

func (*Manager) Rollback added in v0.2.0

func (m *Manager) Rollback(ctx context.Context) (string, error)

Rollback returns the public site to the choice before the current one, naming it.

type ManagerConfig added in v0.2.0

type ManagerConfig struct {
	// Library is the managed themes directory.
	Library *Library
	// Settings persists which theme is active.
	Settings Settings
	// Pinned is the theme an operator fixed by environment, empty when the stored choice governs.
	Pinned string
	// Supervision is how an activated theme is run. The manager fills in the theme itself.
	Supervision SupervisorConfig
}

ManagerConfig carries what a manager needs to run the themes it installs.

type Refusal added in v0.2.0

type Refusal struct {
	// Code names the rule the theme broke, for a client that translates it.
	Code string
	// Reason names the rule the theme broke, in words fit for an admin screen.
	Reason string
	// Detail is what went wrong underneath, for the log.
	Detail error
	// Held names the values the reason's translation asks for.
	Held map[string]any
}

Refusal reports a theme turned away, carrying the reason an operator reads.

func (*Refusal) Error added in v0.2.0

func (r *Refusal) Error() string

Error returns the reason followed by the detail behind it.

func (*Refusal) Unwrap added in v0.2.0

func (r *Refusal) Unwrap() error

Unwrap returns the error the refusal was raised over.

type Settings added in v0.2.0

type Settings interface {
	// Lookup returns the value stored under key and whether the key is set at all.
	Lookup(ctx context.Context, key string) (string, bool, error)
	// Save stores every given value, or stores none of them.
	Save(ctx context.Context, values map[string]string) error
}

Settings persists the operator's theme choices.

type Supervisor

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

Supervisor runs one theme server and keeps it running.

func NewSupervisor

func NewSupervisor(config SupervisorConfig) *Supervisor

NewSupervisor returns a supervisor for one theme.

func (*Supervisor) Await added in v0.2.0

func (s *Supervisor) Await(ctx context.Context) error

Await blocks until the theme serves, the supervisor gives up, or ctx ends.

func (*Supervisor) Group

func (s *Supervisor) Group() int

Group returns the process group the theme runs in, zero while it is down.

func (*Supervisor) Healthy

func (s *Supervisor) Healthy() bool

Healthy reports whether the theme is serving.

func (*Supervisor) Name added in v0.2.0

func (s *Supervisor) Name() string

Name returns the theme the supervisor runs.

func (*Supervisor) Start

func (s *Supervisor) Start()

Start runs the theme until Stop is called.

func (*Supervisor) Stop

func (s *Supervisor) Stop()

Stop ends the theme and waits for its process group to go.

func (*Supervisor) Target

func (s *Supervisor) Target() string

Target returns the address the theme serves on, empty while it is down.

type SupervisorConfig

type SupervisorConfig struct {
	Theme        *Theme
	NodeBin      string
	APIAddr      string
	Logger       *slog.Logger
	ReadyTimeout time.Duration
	Backoff      time.Duration
	MaxBackoff   time.Duration
	MaxAttempts  int
	StopGrace    time.Duration
	StubDelay    time.Duration
}

SupervisorConfig is what a supervisor needs to run one theme.

type Theme

type Theme struct {
	Name    string
	Version string
	Kit     string
	Dir     string
	Entry   string
}

Theme is a validated theme directory.

func Install added in v0.2.0

func Install(themesDir, name string, archive io.ReaderAt, size int64) (*Theme, error)

Install unpacks archive as the named theme, replacing it only once it validates.

func Load

func Load(themesDir, name string) (*Theme, error)

Load returns the theme installed under a name, or nothing when no theme is named.

Jump to

Keyboard shortcuts

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