plugin

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2026 License: Apache-2.0 Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Name     string `yaml:"name" json:"name"`
	Endpoint string `yaml:"endpoint" json:"endpoint"`
	Timeout  string `yaml:"timeout,omitempty" json:"timeout,omitempty"`
}

Config mirrors plugins: section in snapshot.

type Plugin

type Plugin struct {
	Name string
	// BeforeRequest can mutate the outgoing upstream request (e.g., add headers, compress).
	BeforeRequest func(ctx context.Context, req *http.Request) error
	// AfterResponse can post-process the upstream response headers (e.g., add quota headers).
	AfterResponse func(ctx context.Context, h http.Header) error
	// Compress is called for tool_result compression (like RTK) — return new body, true if modified.
	Compress func(body []byte) ([]byte, bool)
	// Endpoint is an HTTP sidecar URL for out-of-process plugins (like caddy).
	// If set, BeforeRequest/AfterResponse are not used; instead the gateway POSTs
	// JSON to endpoint + "/before" or "/after" with 10ms timeout.
	Endpoint string
	Timeout  time.Duration
}

Plugin is a gateway extension. It can be in-process (Go func) or out-of-process HTTP sidecar (endpoint). This mirrors dsh's seam idea but pragmatic for Go gateway:

Service Definition = Hook func signature
Service Provider = Plugin struct (in-process or HTTP sidecar)
Consumer = proxy/router (calls Registry.Hooks)

type Registry

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

Registry holds all registered plugins. Like dsh's Cordis context, but simple.

func NewRegistry

func NewRegistry() *Registry

func (*Registry) AfterResponse

func (r *Registry) AfterResponse(ctx context.Context, h http.Header) error

AfterResponse runs all plugins' AfterResponse hooks.

func (*Registry) BeforeRequest

func (r *Registry) BeforeRequest(ctx context.Context, req *http.Request) error

BeforeRequest runs all plugins' BeforeRequest hooks. If any returns error, the request is aborted.

func (*Registry) List

func (r *Registry) List() []*Plugin

func (*Registry) Register

func (r *Registry) Register(p *Plugin) error

func (*Registry) Unregister

func (r *Registry) Unregister(name string)

Jump to

Keyboard shortcuts

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