contextrouter

package
v0.0.0-...-8e96db4 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2015 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GET     Method = "GET"
	DELETE         = "DELETE"
	HEAD           = "HEAD"
	OPTIONS        = "OPTIONS"
	PATCH          = "PATHCH"
	POST           = "POST"
	PUT            = "PUT"
)

Supported HTTP Methods for use with Server.Handle and Server.HandlerFunc

Variables

This section is empty.

Functions

This section is empty.

Types

type ContextHandler

type ContextHandler interface {
	ServeHTTP(c context.Context, w http.ResponseWriter, r *http.Request)
}

ContextHandler is analogous to http.Handler but takes a Context as the first parameter. Shutdown signals, named routing parameters and any global key value settings are passed via context. Handlers can pass the context to other go functions across API bounndries

func ContextWrapper

func ContextWrapper(h http.Handler) ContextHandler

ContextWrapper is a convenience wrapper for http.Handler into ContextHandler. Do not use this if you have long-running routines.

type ContextHandlerFunc

type ContextHandlerFunc func(c context.Context, w http.ResponseWriter, r *http.Request)

ContextHandlerFunc is analogous to http.HandlerFunc similar to ContextHandler

func (ContextHandlerFunc) ServeHTTP

ServeHTTP enables ContextHandlerFunc to satisfy the ContextHandler interface

type ContextRouter

type ContextRouter struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

ContextRouter is an http router integrating a context.

func New

func New() *ContextRouter

New initializes and returns a new router.

func (*ContextRouter) Handle

func (s *ContextRouter) Handle(method Method, path string, handler ContextHandler)

Handle registers a ContextHandler for the required method and route. See https://github.com/julienschmidt/httprouter for details on named parameters.

func (*ContextRouter) HandleFunc

func (s *ContextRouter) HandleFunc(method Method, path string, handler func(context.Context, http.ResponseWriter, *http.Request))

HandleFunc registers a ContextHandlerFunc for the required method and route. See https://github.com/julienschmidt/httprouter for details on named parameters.

func (*ContextRouter) ServeHTTP

func (s *ContextRouter) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP routes requests to the appropriate handlers

func (*ContextRouter) Stop

func (s *ContextRouter) Stop()

Stop closes the done channel of the root Context of the server to signal to any long running handlers to stop their work.

type Method

type Method string

Method denotes a HTTP method to be specified to the Router

Jump to

Keyboard shortcuts

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