web

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2020 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Overview

Package web contains several handlers supporting the development of web applications and RESTful APIs.

Index

Constants

View Source
const (
	// MethodAll allows to define a handle for all non-explicit
	// configured HTTP methods.
	MethodAll = "*"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ConnectHandler

type ConnectHandler interface {
	ServeHTTPConnect(w http.ResponseWriter, r *http.Request)
}

ConnectHandler has to be implemented by a handler for CONNECT requests dispatched through the MetaMethodHandler.

type DeleteHandler

type DeleteHandler interface {
	ServeHTTPDelete(w http.ResponseWriter, r *http.Request)
}

DeleteHandler has to be implemented by a handler for DELETE requests dispatched through the MetaMethodHandler.

type GetHandler

type GetHandler interface {
	ServeHTTPGet(w http.ResponseWriter, r *http.Request)
}

GetHandler has to be implemented by a handler for HEAD requests dispatched through the MetaMethodHandler.

type HeadHandler

type HeadHandler interface {
	ServeHTTPHead(w http.ResponseWriter, r *http.Request)
}

HeadHandler has to be implemented by a handler for HEAD requests dispatched through the MetaMethodHandler.

type JWTHandler

type JWTHandler struct {
	// contains filtered or unexported fields
}

JWTHandler checks for a valid token and then runs a gatekeeper function.

func NewJWTHandler

func NewJWTHandler(handler http.Handler, config *JWTHandlerConfig) *JWTHandler

NewJWTHandler creates a handler checking for a valid JSON Web Token in each request.

func (*JWTHandler) ServeHTTP

func (jw *JWTHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements the http.Handler interface. It checks for an existing and valid token before calling the wrapped handler.

type JWTHandlerConfig

type JWTHandlerConfig struct {
	Cache      *cache.Cache
	Key        token.Key
	Leeway     time.Duration
	Gatekeeper func(w http.ResponseWriter, r *http.Request, claims token.Claims) error
}

JWTHandlerConfig allows to control how the JWT handler works. All values are optional. In this case tokens are only decoded without using a cache, validated for the current time plus/minus a minute leeway, and there's no user defined gatekeeper function running afterwards.

type MetaMethodHandler

type MetaMethodHandler struct {
	// contains filtered or unexported fields
}

MetaMethodHandler checks if the handler contains a handler with a matching interface for the HTTP method.

func NewMetaMethodHandler

func NewMetaMethodHandler(handler http.Handler) *MetaMethodHandler

NewMetaMethodHandler creates a meta HTTP method handler.

func (*MetaMethodHandler) ServeHTTP

func (mmh *MetaMethodHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements http.Handler.

type MethodHandler

type MethodHandler struct {
	// contains filtered or unexported fields
}

MethodHandler distributes request depending on the HTTP method to subhandlers.

func NewMethodHandler

func NewMethodHandler() *MethodHandler

NewMethodHandler creates an empty HTTP method handler.

func (*MethodHandler) Handle

func (mh *MethodHandler) Handle(method string, handler http.Handler)

Handle adds the handler based on the method.

func (*MethodHandler) HandleFunc

func (mh *MethodHandler) HandleFunc(method string, hf func(http.ResponseWriter, *http.Request))

HandleFunc adds the handler function based on the method.

func (*MethodHandler) ServeHTTP

func (mh *MethodHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements http.Handler.

type NestedHandler

type NestedHandler struct {
	// contains filtered or unexported fields
}

NestedHandler allows to nest handler following the pattern /handlerA/{entityID-A}/handlerB/{entityID-B}.

func NewNestedHandler

func NewNestedHandler() *NestedHandler

NewNestedHandler creates an empty nested handler.

func (*NestedHandler) AppendHandler

func (nh *NestedHandler) AppendHandler(id string, h http.Handler)

AppendHandler adds one handler to the stack of handlers.

func (*NestedHandler) AppendHandlerFunc

func (nh *NestedHandler) AppendHandlerFunc(id string, hf func(http.ResponseWriter, *http.Request))

AppendHandlerFunc adds one handler function to the stack of handlers.

func (*NestedHandler) ServeHTTP

func (nh *NestedHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements http.Handler.

type OptionsHandler

type OptionsHandler interface {
	ServeHTTPOptions(w http.ResponseWriter, r *http.Request)
}

OptionsHandler has to be implemented by a handler for OPTIONS requests dispatched through the MetaMethodHandler.

type PatchHandler

type PatchHandler interface {
	ServeHTTPPatch(w http.ResponseWriter, r *http.Request)
}

PatchHandler has to be implemented by a handler for PATCH requests dispatched through the MetaMethodHandler.

type PostHandler

type PostHandler interface {
	ServeHTTPPost(w http.ResponseWriter, r *http.Request)
}

PostHandler has to be implemented by a handler for POST requests dispatched through the MetaMethodHandler.

type PutHandler

type PutHandler interface {
	ServeHTTPPut(w http.ResponseWriter, r *http.Request)
}

PutHandler has to be implemented by a handler for PUT requests dispatched through the MetaMethodHandler.

type TraceHandler

type TraceHandler interface {
	ServeHTTPTrace(w http.ResponseWriter, r *http.Request)
}

TraceHandler has to be implemented by a handler for TRACE requests dispatched through the MetaMethodHandler.

Jump to

Keyboard shortcuts

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