Documentation
¶
Index ¶
- func DefaultErrorHandler(w http.ResponseWriter, r *http.Request, err error)
- func ToHTTPHandler(h Handler, errHandler ErrorHandler) http.Handler
- type ErrorHandler
- type Handler
- type HandlerFunc
- type InjectionContext
- type InjectionLevel
- type Middleware
- type MiddlewareHook
- type OnRequestHooker
- type Plugin
- type PluginFactory
- type RequestModifier
- type TripperHooker
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultErrorHandler ¶ added in v0.0.37
func DefaultErrorHandler(w http.ResponseWriter, r *http.Request, err error)
DefaultErrorHandler is the default error handler used by Ika. It writes the error to the response in JSON format if the client accepts JSON, otherwise it writes the error as plain text.
If the error implements the following interfaces:
status() int typeURI() string title() string detail() string
The response will be populated with the appropriate values.
func ToHTTPHandler ¶ added in v0.0.31
func ToHTTPHandler(h Handler, errHandler ErrorHandler) http.Handler
ToHTTPHandler converts an Handler into an http.Handler using HandlerFunc.ToHTTPHandler.
Types ¶
type ErrorHandler ¶ added in v0.0.32
type ErrorHandler func(w http.ResponseWriter, r *http.Request, err error)
ErrorHandler is a function that handles errors that occur during request processing.
type Handler ¶ added in v0.0.31
type Handler interface {
ServeHTTP(w http.ResponseWriter, r *http.Request) error
}
Handler is identical to http.Handler except that it is able to return an error.
type HandlerFunc ¶ added in v0.0.31
type HandlerFunc func(http.ResponseWriter, *http.Request) error
HandlerFunc is an adapter to allow the use of ordinary functions as [Handler]s.
func (HandlerFunc) ServeHTTP ¶ added in v0.0.31
func (f HandlerFunc) ServeHTTP(w http.ResponseWriter, r *http.Request) error
func (HandlerFunc) ToHTTPHandler ¶ added in v0.0.31
func (f HandlerFunc) ToHTTPHandler(errHandler ErrorHandler) http.Handler
ToHTTPHandler converts an Handler into an http.Handler. If the function returns an error, it will be written to the response using the provided error handler. If the error handler is nil, the error will be written as a 500 Internal Server Error.
type InjectionContext ¶ added in v0.0.31
type InjectionContext struct {
// Namespace indicates the namespace where the plugin is injected.
// It is empty if not injected at the namespace or route level.
Namespace string
// RoutePattern specifies the route pattern where the plugin is injected.
// It is empty if not injected at the route level.
RoutePattern string
// Level indicates whether the injection is at the namespace or route level.
Level InjectionLevel
// Logger is the logger meant for the plugin.
Logger *slog.Logger
}
InjectionContext contains information about the context in which a plugin is injected.
type InjectionLevel ¶ added in v0.0.31
type InjectionLevel uint8
InjectionLevel defines the granularity of plugin injection.
const ( // LevelRoute specifies injection on a route level. LevelRoute InjectionLevel = iota // LevelNamespace specifies injection on a namespace level. LevelNamespace )
type Middleware ¶ added in v0.0.31
type Middleware interface {
Plugin
// Handler wraps the given handler with custom logic for processing requests and responses.
Handler(next Handler) Handler
}
Middleware enables plugins to modify both requests and responses.
type MiddlewareHook ¶ added in v0.0.31
type MiddlewareHook interface {
// HookMiddleware wraps the provided HTTP handler with custom middleware logic.
HookMiddleware(ctx context.Context, name string, next http.Handler) (http.Handler, error)
}
TODO
type OnRequestHooker ¶ added in v0.0.32
type OnRequestHooker interface {
Plugin
Middleware
}
OnRequestHooker enables hooks that run when a request is received.
It is semantically equivalent to a middleware, but is executed before all other middleware and thus is useful for things such as tracing or logging.
type Plugin ¶ added in v0.0.31
type Plugin interface {
// Setup initializes the plugin with the given configuration and context.
//
// If injected multiple times at the same level, Setup will be called multiple times.
Setup(ctx context.Context, ictx InjectionContext, config map[string]any) error
// Teardown cleans up potential resources used by the plugin.
Teardown(ctx context.Context) error
}
Plugin is the common interface for all plugins in Ika.
type PluginFactory ¶ added in v0.0.31
type PluginFactory interface {
// Name returns the name of the plugin created by this factory.
Name() string
// New creates a new instance of the plugin.
New(ctx context.Context, ictx InjectionContext) (Plugin, error)
}
PluginFactory creates new instances of a plugin.
type RequestModifier ¶ added in v0.0.31
type RequestModifier interface {
Plugin
// ModifyRequest processes and returns the modified HTTP request.
ModifyRequest(r *http.Request) error
}
RequestModifier allows plugins to modify incoming HTTP requests before processing.
type TripperHooker ¶ added in v0.0.31
type TripperHooker interface {
Plugin
// HookTripper returns a new or modified [http.RoundTripper].
// It can wrap or replace the existing transport.
HookTripper(tripper http.RoundTripper) (http.RoundTripper, error)
}
TripperHooker allows plugins to modify the http.RoundTripper used by Ika.
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
ika
command
|
|
|
example
module
|
|
|
internal
|
|
|
http/router/chain
Package chain provides a convenient way to chain http handlers.
|
Package chain provides a convenient way to chain http handlers. |
|
Package plugins contains built-in plugins for the ika API Gateway.
|
Package plugins contains built-in plugins for the ika API Gateway. |
|
accesslog
module
|
|
|
basicauth
module
|
|
|
fail2ban
module
|
|
|
reqmodifier
module
|
|
|
requestid
module
|
|
|
pluginutil
module
|