routing

package
v0.0.0-...-f8253d0 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2018 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Chain

type Chain []func(http.Handler) http.Handler

Chain is an helper to chain middleware handlers together for an easier management.

func (Chain) Handler

func (c Chain) Handler(h http.Handler) http.Handler

Handler wraps the provided final handler with all the middleware appended to the chain and return a new standard http.Handler instance. The context.Background() context is injected automatically.

func (Chain) HandlerF

func (c Chain) HandlerF(hf http.HandlerFunc) http.Handler

HandlerF is an helper to provide a standard http handler function (http.HandlerFunc) to Handler().

func (*Chain) Use

func (c *Chain) Use(f func(next http.Handler) http.Handler)

Use appends a context-aware handler to the middleware chain.

Caveat: the f function will be called on each request so you are better to put any initialization sequence outside of this function.

type HTTPRouter

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

HTTPRouter default router implementation for api2go

func (HTTPRouter) Handle

func (h HTTPRouter) Handle(protocol, route string, handler http.HandlerFunc)

Handle each method like before and wrap them into julienschmidt handler func style

func (HTTPRouter) Handler

func (h HTTPRouter) Handler() http.Handler

Handler returns the router

func (HTTPRouter) Param

func (h HTTPRouter) Param(ctx context.Context, name string) string

func (HTTPRouter) SetParam

func (h HTTPRouter) SetParam(ctx context.Context, name, value string)

func (HTTPRouter) SetRedirectTrailingSlash

func (h HTTPRouter) SetRedirectTrailingSlash(enabled bool)

SetRedirectTrailingSlash wraps this internal functionality of the julienschmidt router.

type HandlerFuncC

type HandlerFuncC func(context.Context, http.ResponseWriter, *http.Request)

type Routeable

type Routeable interface {
	// Handler should return the routers main handler, often this is the router itself
	Handler() http.Handler
	// Handle must be implemented to register api2go's default routines
	// to your used router.
	// protocol will be PATCH,OPTIONS,GET,POST,PUT
	// route will be the request route /items/:id where :id means dynamically filled params
	// handler is the handler that will answer to this specific route
	Handle(protocol, route string, handler http.HandlerFunc)

	Param(context.Context, string) string
	SetParam(context.Context, string, string)
}

Routeable allows drop in replacement for api2go's router by default, we are using julienschmidt/httprouter but you can use any router that has similiar features e.g. gin

func NewHTTPRouter

func NewHTTPRouter(prefix string, notAllowedHandler http.Handler) Routeable

NewHTTPRouter returns a new instance of julienschmidt/httprouter this is the default router when using api2go

Jump to

Keyboard shortcuts

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