Documentation
¶
Overview ¶
Package themehost validates and runs the prebuilt theme artifacts a site is served from.
Index ¶
- Constants
- Variables
- func NewestKit() string
- func ServedKits() []string
- func ServesKit(declared string) bool
- type Error
- type Holder
- type Installed
- type Library
- type Manager
- func (m *Manager) Activate(ctx context.Context, name string) error
- func (m *Manager) Boot(ctx context.Context) error
- func (m *Manager) Close()
- func (m *Manager) Deactivate(ctx context.Context) error
- func (m *Manager) Holder() *Holder
- func (m *Manager) Install(ctx context.Context, name string, archive io.ReaderAt, size int64) error
- func (m *Manager) List(ctx context.Context) ([]Installed, error)
- func (m *Manager) Previous(ctx context.Context) (string, bool, error)
- func (m *Manager) Rollback(ctx context.Context) (string, error)
- type ManagerConfig
- type Settings
- type Supervisor
- type SupervisorConfig
- type Theme
Constants ¶
const ActiveKey = "theme.active"
ActiveKey is the setting naming the theme the public site is served through.
const MaxEntries = 10_000
MaxEntries is how many files an archive may carry.
const MaxSize = 64 << 20
MaxSize is the largest a theme directory may be.
const PreviousKey = "theme.previous"
PreviousKey is the setting naming the theme a rollback returns to.
Variables ¶
var ErrNotInstalled = errors.New("themehost: theme not installed")
ErrNotInstalled reports that no theme is installed under the name.
var ErrStartFailed = errors.New("themehost: the theme did not start")
ErrStartFailed reports a theme the supervisor stopped trying to start.
var ErrStopped = errors.New("themehost: the theme was stopped")
ErrStopped reports a theme the supervisor was told to stop.
Functions ¶
func NewestKit ¶ added in v0.9.0
func NewestKit() string
NewestKit returns the newest theme kit version this release serves.
func ServedKits ¶ added in v0.9.0
func ServedKits() []string
ServedKits returns the theme kit versions this release serves.
Types ¶
type Error ¶ added in v0.9.0
type Error 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
}
Error reports a theme turned away, carrying the reason an operator reads.
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) Serving ¶ added in v0.2.0
Serving returns the theme answering the public site, and whether it is answering.
func (*Holder) StartFailed ¶ added in v0.10.0
StartFailed reports whether the held theme stopped trying to start.
func (*Holder) Swap ¶ added in v0.2.0
func (h *Holder) Swap(next *Supervisor) *Supervisor
Swap holds next instead, returning the supervisor it held.
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
// StartFailed reports whether the supervisor stopped trying to start this theme.
StartFailed 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
NewLibrary returns the library over a managed themes directory.
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
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
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
Deactivate returns the public site to the built-in renderer.
func (*Manager) Holder ¶ added in v0.2.0
Holder returns the theme the public site is served through.
func (*Manager) Install ¶ added in v0.2.0
Install unpacks the archive as the named theme, refusing to replace the active one.
func (*Manager) List ¶ added in v0.2.0
List returns the installed themes, marking the chosen one and the one serving.
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 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, its start fails, it is stopped, 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) StartFailed ¶ added in v0.10.0
func (s *Supervisor) StartFailed() bool
StartFailed reports whether the supervisor stopped retrying the theme.
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.