plugin

package
v0.4.7 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultTimeout = 5 * time.Second // DefaultTimeout defines the maximum time allowed for plugin processing
)

Variables

View Source
var (
	ErrFailedToRead = errors.New("Failed to read plugin directory")
	ErrFailedToLoad = errors.New("Failed to load plugin")
)
View Source
var (
	ResultContinue = &Result{action: Continue}
	ResultModify   = &Result{action: Modify}
)

Functions

This section is empty.

Types

type Action

type Action int

Action represents what the proxy should do with the request/response

const (
	// Continue indicates that the request/response should proceed normally
	Continue Action = iota
	// Stop indicates that the request/response should be stopped
	Stop
	// Modify indicates that the request/response has been modified and should proceed
	Modify
)

type Handler

type Handler interface {
	// ProcessRequest processes the request before it's sent to the backend
	ProcessRequest(ctx context.Context, req *http.Request) *Result

	// ProcessResponse processes the response before it's sent back to the client
	ProcessResponse(ctx context.Context, resp *http.Response) *Result

	Name() string
	Priority() int
	Cleanup() error
}

Handler defines the interface that all plugins must implement

type Manager

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

Manager handles loading, initialization, and execution of plugins

func NewManager

func NewManager(logger *zap.Logger) *Manager

NewManager creates a Manager instance with initial capacity of 10 plugins

func (*Manager) Initialize

func (pm *Manager) Initialize(ctx context.Context, pluginDir string) error

Initialize loads all .so plugin files from the specified directory. Plugins are sorted by priority after loading. Context is used to cancel the initialization process.

func (*Manager) IsEnabled

func (pm *Manager) IsEnabled() bool

IsEnabled returns whether the plugin manager is currently enabled.

func (*Manager) ProcessRequest

func (pm *Manager) ProcessRequest(req *http.Request) *Result

ProcessRequest executes plugins in priority order for HTTP requests. Returns early on timeout or if a plugin returns Stop action.

func (*Manager) ProcessResponse

func (pm *Manager) ProcessResponse(resp *http.Response) *Result

ProcessResponse executes plugins in priority order for HTTP responses. Returns early on context cancellation or if a plugin returns Stop action.

func (*Manager) Shutdown

func (pm *Manager) Shutdown(ctx context.Context) error

Shutdown cleans up all plugins and disables the manager.

type Result

type Result struct {
	StatusCode   int
	ResponseBody []byte
	Headers      http.Header
	// contains filtered or unexported fields
}

Result represents the outcome of plugin processing

func NewResult

func NewResult(action Action, opts ...ResultOption) *Result

NewResult creates a new result with options

func (*Result) Action

func (r *Result) Action() Action

Action returns the result action

func (*Result) Release

func (r *Result) Release()

Release returns the result to the pool

type ResultOption

type ResultOption func(*Result)

ResultOption is a function that modifies a result

func WithHeaders

func WithHeaders(headers http.Header) ResultOption

WithHeaders adds headers

func WithJSONResponse

func WithJSONResponse(v interface{}) ResultOption

WithJSONResponse sets a JSON response body

func WithStatus

func WithStatus(code int) ResultOption

WithStatus sets the status code

Jump to

Keyboard shortcuts

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