Documentation
¶
Overview ¶
Package plugin provides the host-side plugin manager for gohttpd.
Plugins are standalone executable binaries that communicate with the host via hashicorp/go-plugin's net/rpc protocol. Each plugin is a single long-running process that can serve multiple HTTP services simultaneously, each identified by a (ServerName, Path) pair.
Architecture ¶
A plugin process manages its own lifecycle (Meta, Start, ShutDown) and can start/stop individual HTTP services (Serve, UnServe). The host calls Serve() for each server/path combination that references the plugin, and the plugin starts an internal HTTP server for each one, returning the listening port. The host then reverse-proxies matching requests to that port.
This allows a single plugin to serve multiple different server/path combinations with different configurations simultaneously, using only one plugin process.
Plugin loading flow:
- Server startup calls LoadPlugins(PluginRoot) from gohttp.go
- LoadPlugins scans the directory for executable files
- For each executable, startPlugin() launches the plugin process via hashicorp/go-plugin
- The host calls Meta() via RPC to get the plugin's name
- The host calls Start() via RPC to initialize plugin resources
- A health monitoring goroutine watches for process exits and auto-restarts
When a route references a plugin name:
- GetHandler(serverName, path, name, options) returns the reverse proxy
- If the (serverName, path) service is not yet started, the host calls Serve(serverName, path, options) to start it and creates a reverse proxy to the returned port
Index ¶
- func DefaultErrorHandler(pluginName string) http.Handler
- func LoadPlugins(pluginRoot string) (int, error)
- type Manager
- func (m *Manager) Get(name string) *PluginInstance
- func (m *Manager) GetHandler(serverName, path, name string, options map[string]interface{}) http.Handler
- func (m *Manager) Register(inst *PluginInstance)
- func (m *Manager) RestartPlugin(name string) error
- func (m *Manager) Shutdown()
- func (m *Manager) UnServe(serverName, path, name string)
- type PluginInstance
- type PluginService
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultErrorHandler ¶
DefaultErrorHandler returns an HTTP handler that returns a 500 error indicating the plugin was not found.
func LoadPlugins ¶
LoadPlugins scans the given directory for executable files and loads them as plugins. Each executable is launched as a child process via hashicorp/go-plugin. Non-executable files, directories, and .so files are silently skipped.
Returns the number of successfully loaded plugins.
Types ¶
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager manages all loaded plugin instances.
func (*Manager) Get ¶
func (m *Manager) Get(name string) *PluginInstance
Get returns the plugin instance for the given name. Returns nil if the plugin does not exist.
func (*Manager) GetHandler ¶
func (m *Manager) GetHandler(serverName, path, name string, options map[string]interface{}) http.Handler
GetHandler returns an http.Handler for the named plugin serving the given server/path combination with the given options.
If the (serverName, path) service is already started, its reverse proxy is returned. Otherwise the host calls Serve(serverName, path, options) to start a new HTTP service within the plugin and creates a reverse proxy to it. This allows a single plugin process to serve multiple server/path combinations with different configurations simultaneously.
func (*Manager) Register ¶
func (m *Manager) Register(inst *PluginInstance)
Register adds a plugin instance to the manager.
func (*Manager) RestartPlugin ¶
RestartPlugin restarts a plugin by name. Returns an error if the plugin is not found or fails to restart.
type PluginInstance ¶
type PluginInstance struct {
Name string // plugin name (from Meta())
ExecPath string // path to the plugin executable
Client *plugin.Client // go-plugin client (manages the plugin process)
PluginImpl protocol.GoHttpPlugin // RPC client to the plugin
// contains filtered or unexported fields
}
PluginInstance represents a running plugin process. A single plugin process can serve multiple HTTP services simultaneously, each identified by a (ServerName, Path) pair.
type PluginService ¶
type PluginService struct {
ServerName string // server name this service belongs to
Path string // path this service serves
Config map[string]interface{} // config used to start this service
Port int // port the plugin's HTTP server is listening on
Proxy *httputil.ReverseProxy // reverse proxy to the plugin's HTTP server
}
PluginService represents a single HTTP service served by a plugin. Each service has its own reverse proxy pointing to the plugin's internal HTTP server for that (ServerName, Path) combination.
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
my-plugin
command
|
|
|
Package protocol defines the shared interface between the gohttpd host and its plugins.
|
Package protocol defines the shared interface between the gohttpd host and its plugins. |
|
Package sdk provides helper types and functions for writing gohttpd plugins.
|
Package sdk provides helper types and functions for writing gohttpd plugins. |