Documentation ¶
Index ¶
- func AddRequestTime(ctx context.Context, rw http.ResponseWriter, r *http.Request, ...)
- func AddTime(ctx context.Context, now time.Time) context.Context
- func RequestTime(ctx context.Context) time.Time
- func ToHTTP(ctx context.Context, c ContextHandler) http.Handler
- type CloseHeader
- type Constructor
- type ConstructorFunc
- type ContextHandler
- type HTTPConstructor
- type Handler
- type HandlerFunc
- type NextConstructor
- type NextHTTP
- type RequestCounter
- type VarAdder
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddRequestTime ¶
func AddRequestTime(ctx context.Context, rw http.ResponseWriter, r *http.Request, next ContextHandler)
AddRequestTime is a web context that adds the current time to the request's context
func RequestTime ¶
RequestTime looks at the context to return the time added with AddTime
Types ¶
type CloseHeader ¶
type CloseHeader struct {
SetCloseHeader int32
}
CloseHeader is used to control when connections should signal they should be closed
func (*CloseHeader) OptionallyAddCloseHeader ¶
func (c *CloseHeader) OptionallyAddCloseHeader(ctx context.Context, rw http.ResponseWriter, r *http.Request, next ContextHandler)
OptionallyAddCloseHeader will set Connection: Close on the response if SetCloseHeader is non zero
type Constructor ¶
type Constructor interface {
CreateMiddleware(next ContextHandler) ContextHandler
}
Constructor defines how we creates context handling middleware
type ConstructorFunc ¶
type ConstructorFunc func(next ContextHandler) ContextHandler
ConstructorFunc allows a func to become a Constructor
func (ConstructorFunc) CreateMiddleware ¶
func (c ConstructorFunc) CreateMiddleware(next ContextHandler) ContextHandler
CreateMiddleware calls the underline function
type ContextHandler ¶
type ContextHandler interface {
ServeHTTPC(ctx context.Context, rw http.ResponseWriter, r *http.Request)
}
ContextHandler is just like http.Handler but also takes a context
func FromHTTP ¶
func FromHTTP(f http.Handler) ContextHandler
FromHTTP creates a ContextHandler from a http.Handler by throwing away the context
type HTTPConstructor ¶
HTTPConstructor is generally discouraged but allows us to turn a normal http.Handler constructor into a context constructor
func (HTTPConstructor) CreateMiddleware ¶
func (h HTTPConstructor) CreateMiddleware(next ContextHandler) ContextHandler
CreateMiddleware creates a middleware layer for a HTTPConstructor. It is unsafe to call this ContextHandler from multiple threads. Our Handler layer will make sure this doesn't happen
type Handler ¶
type Handler struct { Ending ContextHandler Chain []Constructor StartingContext context.Context Pool sync.Pool }
Handler turns a stack of HTTP handlers into a single handler that threads a context between each
func NewHandler ¶
func NewHandler(StartingContext context.Context, Ending ContextHandler) *Handler
NewHandler creates a new handler with no middleware layers
func (*Handler) Add ¶
func (h *Handler) Add(parts ...Constructor) *Handler
Add a middleware layer to this handler
func (*Handler) ServeHTTP ¶
func (h *Handler) ServeHTTP(rw http.ResponseWriter, r *http.Request)
ServeHTTP passes the default starting context
func (*Handler) ServeHTTPC ¶
ServeHTTPC will pass the request between each middleware layer
type HandlerFunc ¶
HandlerFunc can turn a func() into a ContextHandler
func (HandlerFunc) ServeHTTPC ¶
func (h HandlerFunc) ServeHTTPC(ctx context.Context, rw http.ResponseWriter, r *http.Request)
ServeHTTPC calls the underline func
type NextConstructor ¶
type NextConstructor func(ctx context.Context, rw http.ResponseWriter, r *http.Request, next ContextHandler)
NextConstructor creates a Constructor that calls the given function to forward requests
func (NextConstructor) CreateMiddleware ¶
func (n NextConstructor) CreateMiddleware(next ContextHandler) ContextHandler
CreateMiddleware returns a middleware layer that passes next to n()
type NextHTTP ¶
NextHTTP is like NextConstructor but when the next praameter is a http.Handler
func (NextHTTP) CreateMiddleware ¶
func (n NextHTTP) CreateMiddleware(next ContextHandler) ContextHandler
CreateMiddleware creates a middleware layer that saves the context for the next layer
type RequestCounter ¶
type RequestCounter struct { TotalConnections int64 ActiveConnections int64 TotalProcessingTimeNs int64 }
RequestCounter is a negroni handler that tracks connection stats
func (*RequestCounter) ServeHTTP ¶
func (m *RequestCounter) ServeHTTP(rw http.ResponseWriter, r *http.Request, next http.Handler)
type VarAdder ¶
type VarAdder struct { Key interface{} Value interface{} }
VarAdder is a middleware layer that adds to the context Key/Value
func (*VarAdder) Generate ¶
func (i *VarAdder) Generate(next ContextHandler) ContextHandler
Generate creates the next middleware layer for VarAdder