Documentation ¶
Index ¶
- Constants
- func Log(v ...interface{})
- type CacheEntry
- type Chain
- type DebugLevel
- type DomainMap
- type Filter
- type Match
- type MatchCandidate
- type Matcher
- type Node
- type Route
- type RouteCache
- type RouteComponentType
- type Router
- func (r *Router) Add(method string, path string) *Route
- func (r *Router) AddFilter(filter Filter)
- func (r *Router) AddStatic(staticRoot string)
- func (r *Router) AddStaticWithPrefix(staticRoot string, prefix string)
- func (r *Router) NewMatcher() *Matcher
- func (r *Router) PrintRoutes()
- func (r *Router) PrintTreeInfo()
- func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)
- func (r *Router) SetDebugLevel(debugLevel DebugLevel)
- func (r *Router) SetErrorHandler(statusCode int, handler http.Handler)
- func (r *Router) SetErrorHandlerFunc(statusCode int, handler http.HandlerFunc)
- func (r *Router) SetGlobalHandler(method string, handler http.Handler)
- func (r *Router) SetGlobalHandlerFunc(method string, handlerFunc http.HandlerFunc)
- func (r *Router) SetStringVariable(variable string, value string)
- func (r *Router) Use(route *Route) *Route
- type StaticLocation
- type Tree
Constants ¶
const ( // HTTPMethodGET - GET http method HTTPMethodGET string = "GET" // HTTPMethodPOST - POST http method HTTPMethodPOST string = "POST" // HTTPMethodPUT - PUT http method HTTPMethodPUT string = "PUT" // HTTPMethodDELETE - DELETE http method HTTPMethodDELETE string = "DELETE" )
const ( // RouteInfoKeyIsRoot - does the route have wildcard parts RouteInfoKeyIsRoot string = "is_root" // RouteInfoKeyDescription - does the route have a catch all part RouteInfoKeyDescription string = "description" )
const RootPath = "/"
RootPath - string representation of the root path
Variables ¶
This section is empty.
Functions ¶
Types ¶
type CacheEntry ¶
type CacheEntry struct { Params map[string]interface{} Route *Route // contains filtered or unexported fields }
CacheEntry - an entry in the route cache
func NotFoundCacheEntry ¶
func NotFoundCacheEntry() CacheEntry
NotFoundCacheEntry - represents the inability to find an entry in the cache
type Chain ¶
Chain allows for chaining of Handlers
func (*Chain) AddFunc ¶
func (ch *Chain) AddFunc(v ...http.HandlerFunc) *Chain
AddFunc adds one or more HandlerFuncs to the end of the chain
type DebugLevel ¶
type DebugLevel int
DebugLevel - debug information output level
const ( // DebugLevelNone - debugging is off DebugLevelNone DebugLevel = 1 << iota // DebugLevelTimings - show timings only DebugLevelTimings // DebugLevelFull - show all debugging information DebugLevelFull )
type DomainMap ¶
type DomainMap struct { // NotFoundHandler - if the (sub)domain is not mapped, call this handler NotFoundHandler http.Handler // contains filtered or unexported fields }
DomainMap - maps (sub)domains to routers
func (*DomainMap) InvalidateMatchedHosts ¶
func (domainMap *DomainMap) InvalidateMatchedHosts()
InvalidateMatchedHosts - resets any matched (sub)domains that have been cached
type Filter ¶
Filter is an interface that can be registered on the Router to apply custom logic to modify the Request or calling Context
type Match ¶
Match represents a matched node in the tree
func NewMatchWithParent ¶
NewMatchWithParent creates a new instance of a match that passes down the values from the parent match
type MatchCandidate ¶
type MatchCandidate struct {
// contains filtered or unexported fields
}
MatchCandidate is a helper class for matching path components
func NewMatchCandidate ¶
func NewMatchCandidate(path string) MatchCandidate
NewMatchCandidate creates a new match candidate instance and initializes if for the first part
func NoMatchCandidate ¶
func NoMatchCandidate() MatchCandidate
NoMatchCandidate represents an empty MatchCandidate
func (MatchCandidate) HasRemainingCandidates ¶
func (mc MatchCandidate) HasRemainingCandidates() bool
HasRemainingCandidates returns true if the MatchCandidate has more candidate parts
func (MatchCandidate) IsNoMatch ¶
func (mc MatchCandidate) IsNoMatch() bool
IsNoMatch returns true if the MatchCandidate equals the NoMatchCandidate value
func (MatchCandidate) NextCandidate ¶
func (mc MatchCandidate) NextCandidate() MatchCandidate
NextCandidate returns the next MatchCandidate in the full path
type Matcher ¶
type Matcher struct { LogMatchTime bool // contains filtered or unexported fields }
Matcher is the global matching engine
func NewMatcher ¶
NewMatcher creates a new instance of the Matcher
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
Node - tree node to store route information
func (*Node) HasChildren ¶
HasChildren returns true if the Node has 1 or more sub-Nodes
func (*Node) RouteForMethod ¶
RouteForMethod returns the route that was defined for the method or nil if no route is defined
type Route ¶
type Route struct { Method string Path string PathFormat string Handler http.Handler Meta map[string]interface{} Info map[string]interface{} }
Route stores all the information about a route
func NewRouteWithMeta ¶
NewRouteWithMeta creates a new Route instance with meta values
func (*Route) HandleFunc ¶
func (rte *Route) HandleFunc(handlerFunc http.HandlerFunc) *Route
HandleFunc adds a wrapped ContextHandlerFunc (to ContextHandler) to the Route
type RouteCache ¶
type RouteCache struct { // Entries - ordered list of cache entries Entries []CacheEntry // MaxEntries - maximum number of items permitted in the cache MaxEntries int // ReorderOnAccess - move the last accessed item to the top ReorderOnAccess bool // contains filtered or unexported fields }
RouteCache - temporary storage for routes
func NewRouteCache ¶
func NewRouteCache() *RouteCache
NewRouteCache - creates a new default RouteCache
func (*RouteCache) Get ¶
func (rc *RouteCache) Get(path string) CacheEntry
Get - fetch a cache entry (if exists)
func (*RouteCache) Put ¶
func (rc *RouteCache) Put(path string, entry CacheEntry)
Put - add an item to the route cache
func (*RouteCache) PutRoute ¶
func (rc *RouteCache) PutRoute(path string, route *Route)
PutRoute - add a route into the route cache
type RouteComponentType ¶
type RouteComponentType int
RouteComponentType - route component types NOTE: variables will be stripped out / replaced so we dont track them
const ( // ComponentTypeFixed - a fixed path component ComponentTypeFixed RouteComponentType = 1 << iota // ComponentTypeWildcard - a wildcard path component ComponentTypeWildcard // ComponentTypeCatchAll - catch all route component ComponentTypeCatchAll )
type Router ¶
type Router struct { // ErrorHandler - generic error handler ErrorHandler http.Handler // ShouldCacheMatchedRoutes - if true then any matched routes should be cached // according to the path they were matched to ShouldCacheMatchedRoutes bool // BeforeChain - a Chain of handlers that will always be executed before the Route handler BeforeChain Chain // contains filtered or unexported fields }
Router is the main routing class
func NewRouter ¶
func NewRouter() *Router
NewRouter - creates a new default instance of the Router type
func (*Router) AddStaticWithPrefix ¶
AddStaticWithPrefix registers a directory to serve static files. prefix value will be added at matching
func (*Router) NewMatcher ¶
NewMatcher returns a new matcher for the given Router
func (*Router) PrintRoutes ¶
func (r *Router) PrintRoutes()
PrintRoutes prints route registration information
func (*Router) PrintTreeInfo ¶
func (r *Router) PrintTreeInfo()
PrintTreeInfo prints debugging information about all registered Routes
func (*Router) SetDebugLevel ¶
func (r *Router) SetDebugLevel(debugLevel DebugLevel)
SetDebugLevel - enables or disables debug mode
func (*Router) SetErrorHandler ¶
SetErrorHandler configures a ContextHandler to handle all errors for the supplied status code
func (*Router) SetErrorHandlerFunc ¶
func (r *Router) SetErrorHandlerFunc(statusCode int, handler http.HandlerFunc)
SetErrorHandlerFunc configures a ContextHandlerFunc to handle all errors for the supplied status code
func (*Router) SetGlobalHandler ¶
SetGlobalHandler configures a ContextHandler to handle all requests for a given method
func (*Router) SetGlobalHandlerFunc ¶
func (r *Router) SetGlobalHandlerFunc(method string, handlerFunc http.HandlerFunc)
SetGlobalHandlerFunc configures a ContextHandlerFunc to handle all requests for a given method
func (*Router) SetStringVariable ¶
SetStringVariable adds a string variable value for substitution
type StaticLocation ¶
type StaticLocation struct {
// contains filtered or unexported fields
}
StaticLocation is a holder for static location information
type Tree ¶
type Tree struct {
// contains filtered or unexported fields
}
Tree - storage for routes
func (*Tree) AddRouteToTree ¶
AddRouteToTree splits the route into Nodes and adds them to the tree