router

package
v6.7.2 Latest Latest
Warning

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

Go to latest
Published: May 2, 2020 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package router trie based on a 256-way trie expressed on the textbook Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne A string symbol table for extended ASCII strings, implemented using a 256-way trie. http://algs4.cs.princeton.edu/code/edu/princeton/cs/algs4/TrieST.java.html

Index

Constants

View Source
const R = 256

R extended ASCII

Variables

This section is empty.

Functions

func DefaultRootHandler

func DefaultRootHandler(w http.ResponseWriter, r *http.Request)

DefaultRootHandler hello world handler

func FromContext

func FromContext(ctx context.Context, param string) string

FromContext returns value for repective param available in context NOte: deprecated, please use FromContextParam

func FromContextParam

func FromContextParam(ctx context.Context, param string) string

FromContextParam returns value for repective param available in context

func NotFoundHandler

func NotFoundHandler(w http.ResponseWriter, r *http.Request)

NotFoundHandler default not found resource json handler

func WithContextParam

func WithContextParam(ctx context.Context, param, val string) context.Context

WithContextParam returns a copy of ctx with param value associated.

Types

type Err

type Err struct {
	Err      error             `json:"-"`
	Status   int               `json:"-"`
	Type     string            `json:"type"`
	Message  string            `json:"message"`
	Code     string            `json:"code,omitempty"`
	Metadata map[string]string `json:"metadata,omitempty"`
}

Err struct containing an error and helper fields

type Handler

type Handler interface {
	ServeHTTP(http.ResponseWriter, *http.Request)
}

Handler is a function type like "net/http" Handler

type HandlerFunc

type HandlerFunc func(http.ResponseWriter, *http.Request)

HandlerFunc is a function type like "net/http" HandlerFunc

func Wrap

func Wrap(h HandlerFunc, middlewares ...Middleware) HandlerFunc

Wrap h with all specified middlewares.

func (HandlerFunc) ServeHTTP

func (fn HandlerFunc) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP calls f(w, r)

type Match

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

Match wraps an Handler and context

func (*Match) ServeHTTP

func (m *Match) ServeHTTP(w http.ResponseWriter, req *http.Request)

type Middleware

type Middleware func(HandlerFunc) HandlerFunc

Middleware wraps an http.HandlerFunc with additional functionality.

type Mux

type Mux interface {
	GET(string, HandlerFunc)
	POST(string, HandlerFunc)
	PUT(string, HandlerFunc)
	DELETE(string, HandlerFunc)
	HandleFunc(string, string, HandlerFunc)
	ServeHTTP(http.ResponseWriter, *http.Request)
	WrapperMiddleware(...Middleware)
}

Mux interface to expose router struct

type Router

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

Router ..

func New

func New() *Router

New creates a new router

func NewRouter

func NewRouter() *Router

NewRouter creates a new router instance

func (*Router) DELETE

func (r *Router) DELETE(path string, handlerFn HandlerFunc)

DELETE is a shortcut for Handle with method "DELETE"

func (*Router) FileServer

func (r *Router) FileServer(path string, root http.Dir)

FileServer returns a handler that serves HTTP requests with the contents of the file system rooted at root.

func (*Router) GET

func (r *Router) GET(path string, handlerFn HandlerFunc)

GET is a shortcut for Handle with method "GET"

func (*Router) Handle

func (r *Router) Handle(method, path string, handler Handler)

Handle takes a method, pattern, and http handler for a route.

func (*Router) HandleFunc

func (r *Router) HandleFunc(method, path string, handlerFn HandlerFunc)

HandleFunc registers the handler function for the given pattern.

func (*Router) NotFoundHandler

func (r *Router) NotFoundHandler(handlerFn HandlerFunc)

NotFoundHandler is configuraton method to alow clients to customize NotFoundHandler

func (*Router) POST

func (r *Router) POST(path string, handlerFn HandlerFunc)

POST is a shortcut for Handle with method "POST"

func (*Router) PUT

func (r *Router) PUT(path string, handler HandlerFunc)

PUT is a shortcut for Handle with method "PUT"

func (*Router) ServeHTTP

func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)

ServeHTTP

func (*Router) WrapperMiddleware

func (r *Router) WrapperMiddleware(mids ...Middleware)

WrapperMiddleware ..

type WrapErr

type WrapErr func(http.ResponseWriter, *http.Request) *Err

WrapErr reduces the repetition of dealing with errors in Handlers returning an error https://blog.golang.org/error-handling-and-go

func (WrapErr) ServeHTTP

func (fn WrapErr) ServeHTTP(w http.ResponseWriter, r *http.Request)

Jump to

Keyboard shortcuts

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