plugin

package
v0.0.0-...-78bb4a5 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2026 License: MIT Imports: 11 Imported by: 1

Documentation

Index

Constants

View Source
const (
	PluginName = "middleware"

	ActionContinue = "continue"
	ActionAbort    = "abort"
)
View Source
const DefaultPluginTimeout = 5 * time.Second

Variables

View Source
var Handshake = goplugin.HandshakeConfig{
	ProtocolVersion:  1,
	MagicCookieKey:   "ZOLLY_PLUGIN",
	MagicCookieValue: "zolly-middleware-v1",
}

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

type ConfigureResult struct {
	Success      bool
	ErrorMessage string
}

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 (c *GRPCClient) HandleRequest(ctx context.Context, req *Request) (*Response, error)

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

type HealthCheckResult struct {
	Healthy bool
	Message string
}

HealthCheckResult is returned from HealthCheck.

type Manager

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

Manager manages the lifecycle of all plugin processes.

func NewManager

func NewManager() *Manager

NewManager creates a new plugin manager.

func (*Manager) GetPlugin

func (m *Manager) GetPlugin(name string) (MiddlewarePlugin, error)

GetPlugin returns a loaded plugin by name.

func (*Manager) LoadPlugin

func (m *Manager) LoadPlugin(name string, binaryPath string, settings map[string]string) error

LoadPlugin starts a plugin binary, performs the handshake, and calls Configure.

func (*Manager) Shutdown

func (m *Manager) Shutdown()

Shutdown kills all plugin processes.

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

type PluginSettings struct {
	Settings map[string]string
}

PluginSettings holds arbitrary config for a plugin.

type Request

type Request struct {
	Method      string
	Path        string
	OriginalURL string
	Headers     map[string]string
	Body        []byte
	QueryParams map[string]string
	ClientIP    string
}

Request represents an incoming HTTP request passed to a plugin.

type Response

type Response struct {
	Action     string
	StatusCode int
	Headers    map[string]string
	Body       []byte
}

Response represents the plugin's decision.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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