Search and commands

↑ ↓ to select · Enter to open · Esc to close

Type to search packages.

vestigo

v1.1.1
github.com/husobee/vestigo

Documentation

pkg.go.dev ↗

Table of contents

↓ to select · Enter to jump· Shift+Enter for source

37 matches

Top ↑

Package vestigo implements a performant, stand-alone, HTTP compliant URL Router for go web applications. Vestigo utilizes a simple radix trie for url route indexing and search, and puts any URL parameters found in a request in the request's Form, much like PAT. Vestigo boasts standards compliance regarding the proper behavior when methods are not allowed on a given resource as well as when a resource isn't found. vestigo also includes built in CORS support on a global and per resource capability.

Variables

AllowTrace

var AllowTrace = false

AllowTrace - Globally allow the TRACE method handling within vestigo url router. This generally not a good idea to have true in production settings, but excellent for testing.

Functions

AddParam

func AddParam(r *http.Request, name, value string)

AddParam - Add a vestigo-style parameter to the request -- useful for middleware Appends :name=value onto a blank request query string or appends &:name=value onto a non-blank request query string

CustomMethodNotAllowedHandlerFunc

func CustomMethodNotAllowedHandlerFunc(f MethodNotAllowedHandlerFunc)

CustomMethodNotAllowedHandlerFunc - This function will allow the caller to set vestigo's methodNotAllowedHandler. This function needs to return an http.Handlerfunc and take in a formatted string of methods that ARE allowed. Follow the convention for methodNotAllowedHandler. Note that if you overwrite you will be responsible for making sure the allowed methods are put into headers

CustomNotFoundHandlerFunc

func CustomNotFoundHandlerFunc(f http.HandlerFunc)

CustomNotFoundHandlerFunc - Specify a Handlerfunc to use for a custom NotFound Handler. Can only be performed once.

Param

func Param(r *http.Request, name string) string

Param - Get a url parameter by name

ParamNames

func ParamNames(r *http.Request) []string

ParamNames - Get a url parameter name list with the leading :

TrimmedParamNames

func TrimmedParamNames(r *http.Request) []string

TrimmedParamNames - Get a url parameter name list without the leading :

Types

CorsAccessControl

type CorsAccessControl struct {
	AllowOrigin      []string
	AllowCredentials bool
	ExposeHeaders    []string
	MaxAge           time.Duration
	AllowMethods     []string
	AllowHeaders     []string
}

CorsAccessControl - Default implementation of Cors

CorsAccessControl.GetAllowCredentials

func (c *CorsAccessControl) GetAllowCredentials() bool

GetAllowCredentials - returns the allow-credentials string representation

CorsAccessControl.GetAllowHeaders

func (c *CorsAccessControl) GetAllowHeaders() []string

GetAllowHeaders - returns the allow-headers string representation

CorsAccessControl.GetAllowMethods

func (c *CorsAccessControl) GetAllowMethods() []string

GetAllowMethods - returns the allow-methods string representation

CorsAccessControl.GetAllowOrigin

func (c *CorsAccessControl) GetAllowOrigin() []string

GetAllowOrigin - returns the allow-origin string representation

CorsAccessControl.GetExposeHeaders

func (c *CorsAccessControl) GetExposeHeaders() []string

GetExposeHeaders - returns the expose-headers string representation

CorsAccessControl.GetMaxAge

func (c *CorsAccessControl) GetMaxAge() time.Duration

GetMaxAge - returns the max-age string representation

CorsAccessControl.Merge

func (c *CorsAccessControl) Merge(c2 *CorsAccessControl) *CorsAccessControl

Merge - Merge the values of one CORS policy into 'this' one

MethodNotAllowedHandlerFunc

type MethodNotAllowedHandlerFunc func(string) func(w http.ResponseWriter, r *http.Request)

Middleware

type Middleware func(http.HandlerFunc) http.HandlerFunc

middleware takes in HandlerFunc (which can be another middleware or handler) and wraps it within another one

Router

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

Router - The main vestigo router data structure

NewRouter

func NewRouter() *Router

NewRouter - Create a new vestigo router

Router.Add

func (r *Router) Add(method, path string, h http.HandlerFunc, middleware ...Middleware)

Add - Add a method/handler combination to the router

Router.Connect

func (r *Router) Connect(path string, handler http.HandlerFunc, middleware ...Middleware)

Connect - Helper method to add HTTP CONNECT Method to router

Router.Delete

func (r *Router) Delete(path string, handler http.HandlerFunc, middleware ...Middleware)

Delete - Helper method to add HTTP DELETE Method to router

Router.Find

func (r *Router) Find(req *http.Request) (h http.HandlerFunc)

Find - Find A route within the router tree

Router.Get

func (r *Router) Get(path string, handler http.HandlerFunc, middleware ...Middleware)

Get - Helper method to add HTTP GET Method to router

Router.GetMatchedPathTemplate

func (r *Router) GetMatchedPathTemplate(req *http.Request) string

GetMatchedPathTemplate - get the path template from the url in the request

Router.Handle

func (r *Router) Handle(path string, handler http.Handler, middleware ...Middleware)

Handle - Helper method to add all HTTP Methods to router

Router.HandleFunc

func (r *Router) HandleFunc(path string, handler http.HandlerFunc, middleware ...Middleware)

HandleFunc - Helper method to add all HTTP Methods to router

Router.Patch

func (r *Router) Patch(path string, handler http.HandlerFunc, middleware ...Middleware)

Patch - Helper method to add HTTP PATCH Method to router

Router.Post

func (r *Router) Post(path string, handler http.HandlerFunc, middleware ...Middleware)

Post - Helper method to add HTTP POST Method to router

Router.Put

func (r *Router) Put(path string, handler http.HandlerFunc, middleware ...Middleware)

Put - Helper method to add HTTP PUT Method to router

Router.ServeHTTP

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

ServeHTTP - implementation of a http.Handler, making Router a http.Handler

Router.SetCors

func (r *Router) SetCors(path string, c *CorsAccessControl)

SetCors - Set per resource Cors Policy. The CorsAccessControl policy passed in will map to the policy that is validated against the "path" resource. This policy will be merged with the global policy, and values will be deduplicated if there are overlaps.

Router.SetGlobalCors

func (r *Router) SetGlobalCors(c *CorsAccessControl)

SetGlobalCors - Settings for Global Cors Options. This takes a *CorsAccessControl policy, and will apply said policy to every resource. If this is not set on the router, CORS functionality is turned off.

Router.Trace

func (r *Router) Trace(path string, handler http.HandlerFunc, middleware ...Middleware)

Trace - Helper method to add HTTP TRACE Method to router

Dependency graph