Documentation
¶
Index ¶
Constants ¶
const (
DefaultTimeout = 5 * time.Second // DefaultTimeout defines the maximum time allowed for plugin processing
)
Variables ¶
var ( ErrFailedToRead = errors.New("Failed to read plugin directory") ErrFailedToLoad = errors.New("Failed to load plugin") )
var ( ResultContinue = &Result{action: Continue} ResultModify = &Result{action: Modify} )
Functions ¶
This section is empty.
Types ¶
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 ¶
NewManager creates a Manager instance with initial capacity of 10 plugins
func (*Manager) Initialize ¶
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) ProcessRequest ¶
ProcessRequest executes plugins in priority order for HTTP requests. Returns early on timeout or if a plugin returns Stop action.
func (*Manager) ProcessResponse ¶
ProcessResponse executes plugins in priority order for HTTP responses. Returns early on context cancellation or if a plugin returns Stop action.
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
type ResultOption ¶
type ResultOption func(*Result)
ResultOption is a function that modifies a result
func WithJSONResponse ¶
func WithJSONResponse(v interface{}) ResultOption
WithJSONResponse sets a JSON response body