plugin

package
v0.0.0-...-eadd4a4 Latest Latest
Warning

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

Go to latest
Published: May 29, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ContextInjector

type ContextInjector interface {
	Inject(r *http.Request) *http.Request
}

ContextInjector is implemented by plugins that need to inject data into the request context on every incoming request.

type ExceptionMapperPlugin

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

ExceptionMapperPlugin maps errors to HTTP status codes and response messages using a hash table.

func LoadExceptionMapper

func LoadExceptionMapper(r *http.Request) *ExceptionMapperPlugin

LoadExceptionMapper retrieves the ExceptionMapperPlugin from the request context.

func NewExceptionMapperPlugin

func NewExceptionMapperPlugin() *ExceptionMapperPlugin

NewExceptionMapperPlugin creates an empty ExceptionMapperPlugin.

func (*ExceptionMapperPlugin) Inject

Inject implements ContextInjector, storing the mapper in the request context.

func (*ExceptionMapperPlugin) Map

func (p *ExceptionMapperPlugin) Map(err error) (statusCode int, message string, ok bool)

Map looks up the status code and message for the given error. Tries direct map lookup first (O(1)), then falls back to errors.Is for wrapped errors (O(n)).

func (*ExceptionMapperPlugin) On

func (p *ExceptionMapperPlugin) On(err error, statusCode int, message string) *ExceptionMapperPlugin

On registers an error → statusCode + message mapping. Supports method chaining.

type HandlerFunc

type HandlerFunc = routing.HandlerFunc

HandlerFunc is an alias so plugin code can reference the handler type without importing routing directly.

type Installer

type Installer interface {
	Install(ctx PluginContext)
}

Installer is implemented by plugins that need one-time initialisation at install time (e.g. registering a codec into CodecRegistry).

type PluginContext

type PluginContext map[reflect.Type]any

PluginContext is a map of all currently registered resources, keyed by type. It is passed to Installer.Install so plugins can look up other resources (e.g. CodecRegistry) without the Router knowing about any concrete types.

type RouteHook

type RouteHook interface {
	RouteAdded(method, path string, f HandlerFunc)
}

RouteHook is implemented by plugins that need to observe route registrations. RouteAdded is called once per route at registration time, before the server starts.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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