Documentation ¶
Overview ¶
Package context implements a simple request-aware HTTP context used by plugins and exposed by the middleware layer, designed to share polymorfic data types across plugins in the middleware call chain.
Context is not thread-safe by default. In case that you support multithread programming in plugins you have to use locks/mutex accordingly.
Index ¶
- type Context
- func (c *Context) Clear()
- func (c *Context) Clone() *Context
- func (c *Context) Copy(req *http.Request)
- func (c *Context) Delete(key interface{})
- func (c *Context) Get(key interface{}) interface{}
- func (c *Context) GetAll() map[interface{}]interface{}
- func (c *Context) GetOk(key interface{}) (interface{}, bool)
- func (c *Context) GetString(key interface{}) string
- func (c *Context) Root() *Context
- func (c *Context) Set(key interface{}, value interface{})
- func (c *Context) SetRequest(req *http.Request)
- func (c *Context) UseParent(ctx *Context)
- type Handler
- type HandlerCtx
- type HandlerFunc
- type ReadCloser
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Context ¶
type Context struct { // Stores the last error for the current Context Error error // Flag if the HTTP transaction was explicitly stopped in some phase Stopped bool // Context can inherit behavior and data from another Context Parent *Context // Reference to the http.Client used in the current HTTP transaction Client *http.Client // Reference to the http.Request used in the current HTTP transaction Request *http.Request // Reference to the http.Response used in the current HTTP transaction Response *http.Response }
Context encapsulates required domain-specific HTTP entities to share data and entities for HTTP transactions in a middleware chain
func (*Context) Clear ¶
func (c *Context) Clear()
Clear clears all stored values from a request’s context
func (*Context) Delete ¶
func (c *Context) Delete(key interface{})
Delete deletes a stored value from a request’s context
func (*Context) Get ¶
func (c *Context) Get(key interface{}) interface{}
Get gets a value by key in the current or parent context
func (*Context) GetAll ¶
func (c *Context) GetAll() map[interface{}]interface{}
GetAll returns all stored context values for a request. Will always return a valid map. Returns an empty map for requests context data previously set
func (*Context) GetOk ¶
GetOk gets a context value from req. Returns (nil, false) if key not found in the request context.
func (*Context) GetString ¶
GetString gets a string context value from req. Returns an empty string if key not found in the request context, or the value does not evaluate to a string
func (*Context) Root ¶
Root returns the root Context looking in the parent contexts recursively. If the current context has no parent context, it will return the Context itself.
func (*Context) Set ¶
func (c *Context) Set(key interface{}, value interface{})
Set sets a value on the current store
func (*Context) SetRequest ¶
SetRequest replaces the context http.Request
type Handler ¶
type Handler interface { // Next handler invokes the next plugin in the middleware // call chain with the given Context Next(*Context) // Stop handler stops the current middleware call chain // with the given Context Stop(*Context) // Error handler reports an error and stops the middleware // call chain with the given Context Error(*Context, error) }
Handler exposes a simple interface providing control flow capabilities to middleware functions
func NewHandler ¶
func NewHandler(fn HandlerCtx) Handler
NewHandler creates a new Handler based on a given HandlerCtx function
type HandlerCtx ¶
type HandlerCtx func(*Context)
HandlerCtx represents a Context only function handler
type HandlerFunc ¶
HandlerFunc represents a middleware function handler interface
type ReadCloser ¶
type ReadCloser interface { io.ReadCloser Clone() ReadCloser Context() map[interface{}]interface{} }
ReadCloser augments the io.ReadCloser interface with a Context() method