web

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2015 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

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 AddTime

func AddTime(ctx context.Context, now time.Time) context.Context

AddTime will add now to the context's time. You can get now later with RequestTime

func RequestTime

func RequestTime(ctx context.Context) time.Time

RequestTime looks at the context to return the time added with AddTime

func ToHTTP

func ToHTTP(ctx context.Context, c ContextHandler) http.Handler

ToHTTP converts a ContextHandler into a http.Handler by calling c() with the added ctx

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

type HTTPConstructor func(next http.Handler) http.Handler

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

func (h *Handler) ServeHTTPC(ctx context.Context, rw http.ResponseWriter, r *http.Request)

ServeHTTPC will pass the request between each middleware layer

type HandlerFunc

type HandlerFunc func(ctx context.Context, rw http.ResponseWriter, r *http.Request)

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

type NextHTTP func(rw http.ResponseWriter, r *http.Request, next http.Handler)

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)

func (*RequestCounter) Stats

func (m *RequestCounter) Stats(dimensions map[string]string) []*datapoint.Datapoint

Stats returns stats on total connections, active connections, and total processing time

func (*RequestCounter) Wrap

func (m *RequestCounter) Wrap(next http.Handler) http.Handler

Wrap returns a handler that forwards calls to next and counts the calls forwarded

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

Jump to

Keyboard shortcuts

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