{"modulePath":"github.com/Rethinger/2papi","version":"v0.4.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package plugin\n\n## Types\n\n```go\ntype Config struct {\n\tName     string `yaml:\"name\" json:\"name\"`\n\tEndpoint string `yaml:\"endpoint\" json:\"endpoint\"`\n\tTimeout  string `yaml:\"timeout,omitempty\" json:\"timeout,omitempty\"`\n}\n```\nConfig mirrors plugins: section in snapshot.\n\n```go\ntype Plugin struct {\n\tName string\n\t// BeforeRequest can mutate the outgoing upstream request (e.g., add headers, compress).\n\tBeforeRequest func(ctx context.Context, req *http.Request) error\n\t// AfterResponse can post-process the upstream response headers (e.g., add quota headers).\n\tAfterResponse func(ctx context.Context, h http.Header) error\n\t// Compress is called for tool_result compression (like RTK) — return new body, true if modified.\n\tCompress func(body []byte) ([]byte, bool)\n\t// Endpoint is an HTTP sidecar URL for out-of-process plugins (like caddy).\n\t// If set, BeforeRequest/AfterResponse are not used; instead the gateway POSTs\n\t// JSON to endpoint + \"/before\" or \"/after\" with 10ms timeout.\n\tEndpoint string\n\tTimeout  time.Duration\n}\n```\nPlugin 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:\n\n\tService Definition = Hook func signature\n\tService Provider = Plugin struct (in-process or HTTP sidecar)\n\tConsumer = proxy/router (calls Registry.Hooks)\n\n```go\ntype Registry struct {\n\t// contains filtered or unexported fields\n}\n```\nRegistry holds all registered plugins. Like dsh's Cordis context, but simple.\n\n```go\nfunc NewRegistry() *Registry\n```\n\n```go\nfunc (r *Registry) AfterResponse(ctx context.Context, h http.Header) error\n```\nAfterResponse runs all plugins' AfterResponse hooks.\n\n```go\nfunc (r *Registry) BeforeRequest(ctx context.Context, req *http.Request) error\n```\nBeforeRequest runs all plugins' BeforeRequest hooks. If any returns error, the request is aborted.\n\n```go\nfunc (r *Registry) List() []*Plugin\n```\n\n```go\nfunc (r *Registry) Register(p *Plugin) error\n```\n\n```go\nfunc (r *Registry) Unregister(name string)\n```\n\n","path":"github.com/Rethinger/2papi/internal/plugin","name":"plugin","synopsis":"","isRedistributable":true}
