Documentation
¶
Overview ¶
Package plugin implements external plugin process management.
Plugins are external executables that communicate with prox over stdin/stdout using line-delimited JSON messages for lifecycle events, and over a Unix socket using length-prefixed msgpack frames for request-response hooks (on_request, on_response, on_connect).
Index ¶
- Constants
- func MarshalEnvelope(hook HookType, data interface{}) ([]byte, error)
- type AuthorizeResult
- type Binding
- type Caller
- func (c *Caller) CallConnect(ctx context.Context, conn *ConnInfo) (*ConnResult, error)
- func (c *Caller) CallRequest(ctx context.Context, req *RequestInfo) (*AuthorizeResult, error)
- func (c *Caller) CallResponse(ctx context.Context, req *RequestInfo, resp *UpstreamResponseInfo) (*ResponseModResult, error)
- func (c *Caller) Close()
- type ConfigureParams
- type ConnInfo
- type ConnResult
- type Envelope
- type HookType
- type Manager
- func (m *Manager) Configure(bindings []*Binding, routes map[string]*RouteInfo)
- func (m *Manager) HasHook(routeID string, hook string) bool
- func (m *Manager) OnConnect(ctx context.Context, routeID string, conn *ConnInfo) (*ConnResult, error)
- func (m *Manager) OnRequest(ctx context.Context, routeID string, req *RequestInfo) (*AuthorizeResult, error)
- func (m *Manager) OnResponse(ctx context.Context, routeID string, req *RequestInfo, ...) (*ResponseModResult, error)
- func (m *Manager) Reconfigure(bindings []*Binding, routes map[string]*RouteInfo)
- func (m *Manager) Start(ctx context.Context) error
- func (m *Manager) Stop()
- type MatchInfo
- type Process
- type Push
- type PushParams
- type Request
- type RequestInfo
- type Response
- type ResponseModResult
- type ResponsePair
- type RouteInfo
- type UpstreamResponseInfo
Constants ¶
const ( MethodConfigure = "configure" MethodSetTargets = "set_targets" MethodReady = "ready" )
Method constants for the stdin/stdout JSON protocol.
const ( HookOnRequest = "on_request" HookOnResponse = "on_response" HookOnConnect = "on_connect" )
Hook names advertised by plugins.
Variables ¶
This section is empty.
Functions ¶
func MarshalEnvelope ¶ added in v0.9.0
MarshalEnvelope creates a framed envelope for the given hook type and data. Uses a pooled buffer to avoid intermediate allocations.
Types ¶
type AuthorizeResult ¶ added in v0.9.0
type AuthorizeResult struct {
Allow bool `msgpack:"ok"`
Drop bool `msgpack:"dr,omitempty"`
Status int `msgpack:"s,omitempty"`
Body string `msgpack:"b,omitempty"`
Headers map[string]string `msgpack:"h,omitempty"`
}
AuthorizeResult is the plugin's verdict for an on_request hook.
type Binding ¶
type Binding struct {
RouteID string
Plugin string // absolute path to plugin binary
Match *MatchInfo
Balancer balancer.Balancer
Timeout time.Duration // per-request plugin call timeout
}
Binding associates a route with a plugin process and its balancer.
type Caller ¶ added in v0.9.0
type Caller struct {
// contains filtered or unexported fields
}
Caller manages a connection pool to a plugin's Unix socket. Each connection handles one request at a time — prox grabs a connection, writes a request frame, reads the response, and returns the connection to the pool. This gives natural concurrency without ID correlation or multiplexing.
func (*Caller) CallConnect ¶ added in v0.9.0
CallConnect sends an on_connect hook and returns the plugin's verdict.
func (*Caller) CallRequest ¶ added in v0.9.0
func (c *Caller) CallRequest(ctx context.Context, req *RequestInfo) (*AuthorizeResult, error)
CallRequest sends an on_request hook and returns the plugin's verdict.
func (*Caller) CallResponse ¶ added in v0.9.0
func (c *Caller) CallResponse(ctx context.Context, req *RequestInfo, resp *UpstreamResponseInfo) (*ResponseModResult, error)
CallResponse sends an on_response hook and returns response modifications.
type ConfigureParams ¶
type ConfigureParams struct {
RouteID string `json:"route_id"`
Match *MatchInfo `json:"match,omitempty"`
}
ConfigureParams is sent to the plugin on startup and after reload.
type ConnInfo ¶ added in v0.9.0
type ConnInfo struct {
RouteID string `msgpack:"r"`
Domain string `msgpack:"d"`
RemoteAddr string `msgpack:"a"`
MatchDomain string `msgpack:"md,omitempty"`
MatchGlob string `msgpack:"mg,omitempty"`
}
ConnInfo carries L4 connection context for on_connect hooks.
type ConnResult ¶ added in v0.9.0
type ConnResult struct {
Allow bool `msgpack:"ok"`
}
ConnResult is the plugin's verdict for an on_connect hook.
type HookType ¶ added in v0.9.0
type HookType byte
HookType identifies the hook being invoked over the socket.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager supervises plugin processes and routes push messages to balancers. It also provides the hook call API (OnRequest, OnResponse, OnConnect) for the HTTP handler and L4 dispatcher.
func NewManager ¶
func NewManager() *Manager
NewManager creates a plugin manager. Call Start() to spawn processes.
func (*Manager) Configure ¶
Configure sets the current route-to-plugin bindings and global route info. Call Start() after Configure() to spawn processes.
func (*Manager) HasHook ¶ added in v0.9.0
HasHook returns true if any plugin bound to the route supports the given hook. Lock-free: reads from the atomic hook index.
func (*Manager) OnConnect ¶ added in v0.9.0
func (m *Manager) OnConnect(ctx context.Context, routeID string, conn *ConnInfo) (*ConnResult, error)
OnConnect calls the on_connect hook for all plugins bound to the route. Sequential execution, short-circuit on first deny.
func (*Manager) OnRequest ¶ added in v0.9.0
func (m *Manager) OnRequest(ctx context.Context, routeID string, req *RequestInfo) (*AuthorizeResult, error)
OnRequest calls the on_request hook for all plugins bound to the route. Sequential execution, short-circuit on first deny.
func (*Manager) OnResponse ¶ added in v0.9.0
func (m *Manager) OnResponse(ctx context.Context, routeID string, req *RequestInfo, resp *UpstreamResponseInfo) (*ResponseModResult, error)
OnResponse calls the on_response hook for all plugins bound to the route.
func (*Manager) Reconfigure ¶
Reconfigure updates bindings and reconfigures running plugins. New plugins are started, removed plugins are stopped.
type MatchInfo ¶
type MatchInfo struct {
Domain string `json:"domain,omitempty"`
Path string `json:"path,omitempty"`
}
MatchInfo provides the route's match criteria to the plugin.
type Process ¶
type Process struct {
// contains filtered or unexported fields
}
Process wraps a single plugin subprocess.
func (*Process) Done ¶
func (p *Process) Done() <-chan struct{}
Done returns a channel that closes when the process exits.
type Push ¶
type Push struct {
Method string `json:"method"`
Params PushParams `json:"params"`
}
Push is a message sent from a plugin to prox via stdout.
type PushParams ¶
type PushParams struct {
RouteID string `json:"route_id,omitempty"`
Action string `json:"action,omitempty"` // target routes by action name
Targets []string `json:"targets,omitempty"`
Groups map[string][]string `json:"groups,omitempty"`
// Ready-specific fields (only when Method == "ready").
Socket string `json:"socket,omitempty"`
Hooks []string `json:"hooks,omitempty"`
}
PushParams carries the data for a push message.
type Request ¶
type Request struct {
Method string `json:"method"`
Params interface{} `json:"params,omitempty"`
}
Request is a message sent from prox to a plugin via stdin.
type RequestInfo ¶ added in v0.9.0
type RequestInfo struct {
RouteID string `msgpack:"r"`
Method string `msgpack:"m"`
Path string `msgpack:"p"`
Query string `msgpack:"q,omitempty"`
Domain string `msgpack:"d"`
Host string `msgpack:"ho,omitempty"`
Proto string `msgpack:"pr,omitempty"`
RemoteAddr string `msgpack:"a"`
ContentLength int64 `msgpack:"cl,omitempty"`
Headers map[string]string `msgpack:"h"`
Body []byte `msgpack:"bd,omitempty"`
MatchDomain string `msgpack:"md,omitempty"`
MatchGlob string `msgpack:"mg,omitempty"`
MatchPath string `msgpack:"mp,omitempty"`
Vars map[string]string `msgpack:"v,omitempty"`
}
RequestInfo carries the HTTP request context for on_request hooks.
type Response ¶
type Response struct {
Result string `json:"result,omitempty"`
Error string `json:"error,omitempty"`
}
Response is a simple acknowledgement from a plugin.
type ResponseModResult ¶ added in v0.9.0
type ResponseModResult struct {
Status int `msgpack:"s,omitempty"`
Headers map[string]string `msgpack:"h,omitempty"`
Remove []string `msgpack:"rm,omitempty"`
}
ResponseModResult describes modifications to apply to the upstream response.
type ResponsePair ¶ added in v0.9.0
type ResponsePair struct {
Req RequestInfo `msgpack:"req"`
Resp UpstreamResponseInfo `msgpack:"resp"`
}
ResponsePair bundles request + upstream response for the on_response hook.
type RouteInfo ¶ added in v0.12.0
RouteInfo describes a route's balancer and action for global target pushes.
type UpstreamResponseInfo ¶ added in v0.9.0
type UpstreamResponseInfo struct {
Status int `msgpack:"s"`
Headers map[string]string `msgpack:"h"`
}
UpstreamResponseInfo carries upstream response context for on_response hooks.