Documentation
¶
Index ¶
- Constants
- Variables
- func NewFiberMiddleware(p MiddlewarePlugin, timeout time.Duration) fiber.Handler
- func NewFiberMiddlewareChain(mgr *Manager, pluginNames []string, timeout time.Duration) ([]fiber.Handler, error)
- func Serve(impl MiddlewarePlugin)
- type ConfigureResult
- type GRPCClient
- type GRPCServer
- func (s *GRPCServer) Configure(ctx context.Context, req *pb.PluginConfig) (*pb.ConfigureResponse, error)
- func (s *GRPCServer) HandleRequest(ctx context.Context, req *pb.HttpRequest) (*pb.HttpResponse, error)
- func (s *GRPCServer) HealthCheck(ctx context.Context, _ *pb.Empty) (*pb.HealthCheckResponse, error)
- type HealthCheckResult
- type Manager
- type MiddlewareGRPCPlugin
- type MiddlewarePlugin
- type PluginInstance
- type PluginSettings
- type Request
- type Response
Constants ¶
const ( PluginName = "middleware" ActionContinue = "continue" ActionAbort = "abort" )
const DefaultPluginTimeout = 5 * time.Second
Variables ¶
var Handshake = goplugin.HandshakeConfig{
ProtocolVersion: 1,
MagicCookieKey: "ZOLLY_PLUGIN",
MagicCookieValue: "zolly-middleware-v1",
}
var PluginMap = map[string]goplugin.Plugin{ PluginName: &MiddlewareGRPCPlugin{}, }
Functions ¶
func NewFiberMiddleware ¶
func NewFiberMiddleware(p MiddlewarePlugin, timeout time.Duration) fiber.Handler
NewFiberMiddleware creates a fiber.Handler that calls the given plugin for every request.
func NewFiberMiddlewareChain ¶
func NewFiberMiddlewareChain(mgr *Manager, pluginNames []string, timeout time.Duration) ([]fiber.Handler, error)
NewFiberMiddlewareChain creates an ordered slice of fiber.Handler from plugin names.
func Serve ¶
func Serve(impl MiddlewarePlugin)
Serve starts the plugin process. Plugin authors call this from main().
Types ¶
type ConfigureResult ¶
ConfigureResult is returned from Configure.
type GRPCClient ¶
type GRPCClient struct {
// contains filtered or unexported fields
}
GRPCClient is the gateway-side implementation of MiddlewarePlugin.
func (*GRPCClient) Configure ¶
func (c *GRPCClient) Configure(ctx context.Context, settings *PluginSettings) (*ConfigureResult, error)
func (*GRPCClient) HandleRequest ¶
func (*GRPCClient) HealthCheck ¶
func (c *GRPCClient) HealthCheck(ctx context.Context) (*HealthCheckResult, error)
type GRPCServer ¶
type GRPCServer struct {
pb.UnimplementedMiddlewarePluginServer
Impl MiddlewarePlugin
}
GRPCServer wraps a MiddlewarePlugin implementation as a gRPC server. This is used inside plugin binaries.
func (*GRPCServer) Configure ¶
func (s *GRPCServer) Configure(ctx context.Context, req *pb.PluginConfig) (*pb.ConfigureResponse, error)
func (*GRPCServer) HandleRequest ¶
func (s *GRPCServer) HandleRequest(ctx context.Context, req *pb.HttpRequest) (*pb.HttpResponse, error)
func (*GRPCServer) HealthCheck ¶
func (s *GRPCServer) HealthCheck(ctx context.Context, _ *pb.Empty) (*pb.HealthCheckResponse, error)
type HealthCheckResult ¶
HealthCheckResult is returned from HealthCheck.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager manages the lifecycle of all plugin processes.
func (*Manager) GetPlugin ¶
func (m *Manager) GetPlugin(name string) (MiddlewarePlugin, error)
GetPlugin returns a loaded plugin by name.
func (*Manager) LoadPlugin ¶
LoadPlugin starts a plugin binary, performs the handshake, and calls Configure.
type MiddlewareGRPCPlugin ¶
type MiddlewareGRPCPlugin struct {
goplugin.Plugin
Impl MiddlewarePlugin
}
MiddlewareGRPCPlugin implements goplugin.GRPCPlugin.
func (*MiddlewareGRPCPlugin) GRPCClient ¶
func (p *MiddlewareGRPCPlugin) GRPCClient(ctx context.Context, broker *goplugin.GRPCBroker, c *grpc.ClientConn) (interface{}, error)
func (*MiddlewareGRPCPlugin) GRPCServer ¶
func (p *MiddlewareGRPCPlugin) GRPCServer(broker *goplugin.GRPCBroker, s *grpc.Server) error
type MiddlewarePlugin ¶
type MiddlewarePlugin interface {
HandleRequest(ctx context.Context, req *Request) (*Response, error)
Configure(ctx context.Context, settings *PluginSettings) (*ConfigureResult, error)
HealthCheck(ctx context.Context) (*HealthCheckResult, error)
}
MiddlewarePlugin is the interface that all middleware plugins must implement.
type PluginInstance ¶
type PluginInstance struct {
Name string
Client *goplugin.Client
Plugin MiddlewarePlugin
}
PluginInstance represents a single running plugin process.
type PluginSettings ¶
PluginSettings holds arbitrary config for a plugin.