Documentation
¶
Overview ¶
Package extensions runs out-of-process gopherstack extensions: executables or container images that register routes and hooks over a local control API.
Index ¶
- Constants
- Variables
- type Config
- type HookResponse
- type HookSet
- type Hooks
- type Info
- type Manager
- func (m *Manager) Enabled() bool
- func (m *Manager) Hooks(service string) *HookSet
- func (m *Manager) List() []Info
- func (m *Manager) MarkReady(ctx context.Context)
- func (m *Manager) Route(r *http.Request, shadowed bool) http.Handler
- func (m *Manager) ServeList(w http.ResponseWriter, _ *http.Request)
- func (m *Manager) ServeRegister(w http.ResponseWriter, r *http.Request)
- func (m *Manager) Start(ctx context.Context)
- func (m *Manager) Stop(ctx context.Context)
- type Options
- type Recorder
- type Registration
- type RequestHook
- type Routes
- type Settings
- type Spec
- type Status
Constants ¶
const ( RestartNever = "never" RestartOnFailure = "on-failure" RestartAlways = "always" )
Restart policies.
Variables ¶
var ( ErrInvalidSpec = errors.New("invalid extension spec") ErrInvalidConfig = errors.New("invalid extensions config") )
Errors returned by config loading and validation.
var ErrInvalidRegistration = errors.New("invalid registration")
ErrInvalidRegistration is returned for a rejected registration payload.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
FailOpen *bool `yaml:"fail_open"`
Extensions []Spec `yaml:"extensions"`
HookTimeout time.Duration `yaml:"hook_timeout"`
}
Config is the extensions config file.
func LoadConfig ¶
LoadConfig merges the config file and inline flags into one validated Config.
func (Config) FailOpenDefault ¶
FailOpenDefault is the fail-open default for request hooks (true unless configured).
type HookResponse ¶
type HookResponse struct {
Headers map[string]string `json:"headers"`
Body []byte `json:"body"`
Status int `json:"status"`
}
HookResponse is a reply an extension (or a failed closed hook) wants sent to the client.
func (*HookResponse) Write ¶
func (r *HookResponse) Write(w http.ResponseWriter)
Write sends the response.
type HookSet ¶
type HookSet struct {
// contains filtered or unexported fields
}
HookSet is the set of request hooks that apply to one service for one request.
type Hooks ¶
type Hooks struct {
OnStartup string `json:"on_startup,omitempty"`
OnReady string `json:"on_ready,omitempty"`
OnShutdown string `json:"on_shutdown,omitempty"`
Request []RequestHook `json:"request,omitempty"`
}
Hooks are the extension's lifecycle and request callbacks (paths on its endpoint).
type Info ¶
type Info struct {
Registration *Registration `json:"registration,omitempty"`
Name string `json:"name"`
Type string `json:"type"`
Status Status `json:"status"`
Endpoint string `json:"endpoint,omitempty"`
LastError string `json:"last_error,omitempty"`
Restarts int `json:"restarts"`
}
Info is the public, token-free view of an extension.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager owns extension lifecycles, claims and hooks.
func (*Manager) Hooks ¶
Hooks returns the request hooks registered for service, or nil when there are none.
func (*Manager) MarkReady ¶
MarkReady fires on_ready for registered extensions and for any that register later.
func (*Manager) Route ¶
Route returns the handler for r if an extension claims it, else nil. shadowed means a built-in service already matched; only allow_override extensions may take such requests.
func (*Manager) ServeList ¶
func (m *Manager) ServeList(w http.ResponseWriter, _ *http.Request)
ServeList handles GET /_gopherstack/extensions.
func (*Manager) ServeRegister ¶
func (m *Manager) ServeRegister(w http.ResponseWriter, r *http.Request)
ServeRegister handles POST /_gopherstack/extensions/register.
type Options ¶
type Options struct {
Logger *slog.Logger
// NewRuntime builds the container runtime on first use; nil disables image extensions.
NewRuntime func() (container.Runtime, error)
// ControlURL is the base URL extensions use to reach the control API.
ControlURL string
}
Options wires the manager to its host.
type Recorder ¶
type Recorder struct {
// contains filtered or unexported fields
}
Recorder buffers a response so post hooks can inspect and rewrite it before Commit.
func NewRecorder ¶
func NewRecorder(w http.ResponseWriter) *Recorder
NewRecorder wraps w; nothing reaches w until Commit.
func (*Recorder) Commit ¶
func (r *Recorder) Commit()
Commit writes the buffered response to the underlying writer.
func (*Recorder) WriteHeader ¶
WriteHeader records the status.
type Registration ¶
type Registration struct {
Name string `json:"name"`
Version string `json:"version,omitempty"`
Endpoint string `json:"endpoint,omitempty"`
Routes Routes `json:"routes"`
Hooks Hooks `json:"hooks"`
}
Registration is the body of POST /_gopherstack/extensions/register.
type RequestHook ¶
type RequestHook struct {
FailOpen *bool `json:"fail_open,omitempty"`
Pre string `json:"pre,omitempty"`
Post string `json:"post,omitempty"`
Services []string `json:"services"`
TimeoutMs int `json:"timeout_ms,omitempty"`
}
RequestHook asks gopherstack to call the extension around matched services.
type Routes ¶
type Routes struct {
PathPrefixes []string `json:"path_prefixes,omitempty"`
Hosts []string `json:"hosts,omitempty"`
TargetPrefixes []string `json:"target_prefixes,omitempty"`
}
Routes are the requests an extension claims.
type Settings ¶
type Settings struct {
Config string `` //nolint:lll // config struct tags are intentionally verbose
/* 138-byte string literal not displayed */
Inline []string `` //nolint:lll // config struct tags are intentionally verbose
/* 149-byte string literal not displayed */
}
Settings is embedded in the root CLI.
type Spec ¶
type Spec struct {
Env map[string]string `yaml:"env"`
Name string `yaml:"name"`
Image string `yaml:"image"`
Restart string `yaml:"restart"`
HealthPath string `yaml:"health_path"`
ControlURL string `yaml:"control_url"`
Command []string `yaml:"command"`
Args []string `yaml:"args"`
Port int `yaml:"port"`
MaxRestarts int `yaml:"max_restarts"`
RestartBackoff time.Duration `yaml:"restart_backoff"`
StartTimeout time.Duration `yaml:"start_timeout"`
HealthInterval time.Duration `yaml:"health_interval"`
HealthTimeout time.Duration `yaml:"health_timeout"`
HealthFailures int `yaml:"health_failures"`
AllowOverride bool `yaml:"allow_override"`
}
Spec declares one extension: either Command (a host process) or Image (a container).
func ParseInline ¶
ParseInline parses name=command args or name=image:REF.