pluginhost

package
v1.61.0 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package pluginhost is the cockpit's side of the plugin package: the public package is contract only, and the implementations behind its interfaces live here, construction, sealing and collection included. The helpers below read the sealed Serves the plugins filled at ConfigureServe and hand each surface exactly the view it renders.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssetPrefix

func AssetPrefix(s *Serve) string

AssetPrefix is the manifest path prefix of one plugin's added assets, without the leading slash, the way the asset manifest names files.

func ServesHTTP

func ServesHTTP(s *Serve) bool

ServesHTTP reports whether the plugin's subtree answers anything, which is what decides whether the router registers it at all.

func SlotHTML

func SlotHTML(serves []*Serve, slot string) template.HTML

SlotHTML concatenates what every plugin added for the named slot. The markup is compiled in plugin code and deliberately not escaped, that is the whole point of a slot.

func Starter

func Starter(s *Serve, resolve func(string) string) (string, bool)

Starter generates the starter module for one plugin: it imports the class module of every added element through resolve, which answers the hashed URL of a raw asset path, and defines each element under its final name with a get guard. False when the plugin added no elements.

func StarterPath

func StarterPath(s *Serve) string

StarterPath is the raw URL of the cockpit's generated starter module for one plugin, the module the import map binds the plugin's element names to. The path is reserved inside the plugin's subtree.

Types

type Element

type Element struct {
	Name string
	URL  string
}

Element is one final element name with the URL of the starter module that defines it, ready for the import map: the lazy loader imports unknown element names, so binding the name to the starter is what loads a plugin's code the first time one of its elements is on a page.

func Elements

func Elements(serves []*Serve, resolve func(string) string) []Element

Elements answers every added element across the Serves, in wiring order, each bound to its plugin's starter through resolve, which answers the hashed URL of a raw asset path.

type Registration

type Registration struct {
	Name   string
	Module string
}

Registration is one added custom element as the cockpit reads it: the final name next to the module path inside the added assets.

type Serve

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

Serve implements plugin.Serve for one wired plugin, and it is also the cockpit's reading side of what that plugin added. What each method means is documented on the plugin package's interfaces, the contract; this is the construction, the sealing and the collection behind it.

func ConfigureServe

func ConfigureServe(plugins []plugin.Named[plugin.ServePlugin], projectsDir, stateDir string, createProject func(ctx context.Context, name string) (string, error), projectChanged func(ctx context.Context) error) ([]*Serve, error)

ConfigureServe runs every pair's ConfigureServe, each with a fresh Serve bound to the pair's id and to the serving instance, and answers the sealed Serves in pair order. It is the cockpit's call at serve start, after the configuration is loaded and before the server listens; the ids are validated before, see distro.Main. createProject is the web UI's own project creation path and projectChanged its announcement path, which is what the projects facade delegates to. A failing plugin aborts the start with its id on the error.

func (*Serve) AddAssets

func (s *Serve) AddAssets(files fs.FS)

func (*Serve) AddCustomElement

func (s *Serve) AddCustomElement(name, module string) plugin.CustomElement

func (*Serve) AddRoutes

func (s *Serve) AddRoutes(handler http.Handler) plugin.Routes

func (*Serve) AddSlotHTML

func (s *Serve) AddSlotHTML(slot, html string)

func (*Serve) Assets

func (s *Serve) Assets() fs.FS

Assets answers the added asset files, nil for none.

func (*Serve) CustomElements

func (s *Serve) CustomElements() []Registration

CustomElements answers the added elements, in call order.

func (*Serve) Handler

func (s *Serve) Handler() http.Handler

Handler answers the added HTTP handler, nil for none.

func (*Serve) ID

func (s *Serve) ID() string

ID answers the wiring id the Serve is bound to.

func (*Serve) Projects

func (s *Serve) Projects() plugin.Projects

func (*Serve) ProjectsDir

func (s *Serve) ProjectsDir() string

func (*Serve) SlotHTML

func (s *Serve) SlotHTML(slot string) string

SlotHTML answers the markup added for a slot, "" for none.

func (*Serve) StateDir

func (s *Serve) StateDir() string

Jump to

Keyboard shortcuts

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