Documentation ¶
Index ¶
- Variables
- func Ampersand(url, prefix, terminators string) string
- func Depth(url string) int
- func PartN(url string, n int) string
- func TrimPast(s, terminators string) string
- func TrimPastRune(s string, r rune) string
- type DomainRouter
- type Handler
- type NoExtPath
- type Path
- func (p Path) AddChild(pR Router, name string) Path
- func (p Path) Child(subpath string) (n Router, remainingSubpath string)
- func (p Path) ChildProcess(subpath string, process func(string) string) (n Router, remainingSubpath string)
- func (p Path) Handler(r Router) Path
- func (p Path) RouteHTTP(rq *http.Request) Router
- type PathingRouter
- type RecoverHandler
- type RecoverHandlerFunc
- type RouteHandler
- type Router
- type RouterFunc
- type Subdomain
- type Verb
- func (p Verb) Delete(hf Router) Verb
- func (p Verb) Get(hf Router) Verb
- func (p Verb) Head(hf Router) Verb
- func (p Verb) Options(hf Router) Verb
- func (p Verb) Patch(hf Router) Verb
- func (p Verb) Post(hf Router) Verb
- func (p Verb) Put(hf Router) Verb
- func (v Verb) RouteHTTP(rq *http.Request) Router
- func (p Verb) Verb(verb string, hf Router) Verb
- func (v Verb) Verbs() (ops []string)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var MethodNotAllowed func(i interface{}, rw http.ResponseWriter, rq *http.Request)
var NotFound http.Handler = http.HandlerFunc(func(rw http.ResponseWriter, rq *http.Request) { rw.Header().Add("Content-Type", "text/plain") rw.WriteHeader(int(fweight.StatusNotFound)) fmt.Fprintf( rw, `A resource could not be found to match your request. Technical Information: Request URI: %+q Method: %+q Protocol: %+q Headers: %+v ContentLength: %v Remote Address: %+q`, rq.Host+rq.URL.Path, rq.Method, rq.Proto, rq.Header, rq.ContentLength, rq.RemoteAddr, ) })
NotFound is a convenience http.Handler for RouteHandler's NotFound.
var OptionsHandler func(i interface{}, rw http.ResponseWriter, rq *http.Request)
Functions ¶
func Ampersand ¶
Function Ampersand is used to retrieve the URL part that was swallowed by an ampersand path. To achieve this, `prefix` is trimmed from the beginning of the url, and the resulting string is returned up until an instance of a char in `terminators` or the end of the string.
Example ¶
name := Ampersand("/user/bob/images/", "/user/", "/") fmt.Println(name) name = Ampersand("/user/anne.html", "/user/", "./") fmt.Println(name) name = Ampersand("/user/anne/images/cat.png", "/user/", "./") fmt.Println(name)
Output: bob anne anne
func PartN ¶
Function PartN returns the Nth part of a URL, separated by '/'. A leading slash ('/usr') is ignored. If there are too few parts, empty string is returned.
Example ¶
name := PartN("/user/bob/images", 1) fmt.Println(name) annepage := PartN("/user/anne.html", 1) fmt.Println(annepage) imagename := PartN("user/anne/imags/cat.png", 3) fmt.Println(imagename) empty := PartN("/user/anne/images/", 3) fmt.Println(empty)
Output: bob anne.html cat.png
func TrimPastRune ¶
Returns s up until r, or the whole string.
Types ¶
type DomainRouter ¶
Internally, the domain system is based on the DomainRouter interface. A DomainRouter will check an assertion that the Router that is recieved from the Subdomain function is a DomainRouter. If is, the RouteHTTP function continues down the trie until this is not the case.
type Handler ¶
A handler represents a termination of the Router B+ tree.
func Handle ¶
Function HandlerOf returns a Handler of a http.Handler, which can be used to terminatr and handle routes.
func HandleFunc ¶
func HandleFunc(hf http.HandlerFunc) Handler
type NoExtPath ¶
type NoExtPath Path
NoExtPath is a PathRouter that ignores the extensions of folders and files when matching request URIs.
type Path ¶
Type Path is a Router which routes by URL path. Files or directories with empty names are not allowed. The empty name routes to the terminal Router, the one used if the path stops here, and the ampersand ("&") path swallows the next file segment in the path, regardless of its contents.
It should be noted that when RouteHTTP is called the PathRouter is followed to completion from the start to end of the URL, thus using two routers separately (i.e. separated by a different Router in the routing tree) causes two separate and independant operations on the path; a Path that routes a/b followed by one that routes a/b/c does not result in a route of a/b/a/c, instead resulting in a route of just a/b.
func (Path) AddChild ¶
Function AddChild adds a child PathRouter which is used as the next name in the path.
A non PathRouter child will cause the Router to be returned to the caller of RouteHTTP, causing the path to terminate there if it is a Handler.
func (Path) Child ¶
Function Child is provided by all types that implement the PathingRouter interface.
func (Path) ChildProcess ¶
func (p Path) ChildProcess(subpath string, process func(string) string) (n Router, remainingSubpath string)
Function Child returns the next Router associated with the next 'hop' in the path.
type PathingRouter ¶
A PathingRouter is part of the filepath, and can take part in the descent of the filepath trie.
type RecoverHandler ¶
type RecoverHandler interface { //'i' is the data the server paniced with. ServeRecover(i interface{}) http.Handler }
var HandleRecovery RecoverHandler = RecoverHandlerFunc(func(i interface{}) http.Handler { return http.HandlerFunc(func(rw http.ResponseWriter, rq *http.Request) { rw.Header().Add("Content-Type", "text/plain") rw.WriteHeader(int(fweight.StatusInternalServerError)) fmt.Fprintf( rw, `An Internal Server Error was encountered while handling your request: %+q`, fmt.Sprint(i), ) log.Printf( "Internal Server Error: %+q\n %s", fmt.Sprint(i), deb.Stack(), ) }) })
HandleRecovery is a convenience RecoverHandler for development builds.
type RecoverHandlerFunc ¶
func (RecoverHandlerFunc) ServeRecover ¶
func (r RecoverHandlerFunc) ServeRecover(i interface{}) http.Handler
type RouteHandler ¶
type RouteHandler struct { Router //NotFound is called when a route for the request could not be found. //Recover is called when there is a panic in a Router. NotFound http.Handler Recover RecoverHandler }
A RouteHandler implements an http.Handler for a tree of Routers. When the RouteHandler is unable to find an http.Handler, or encounters an error while handling a response, it uses the NotFound and InternalServerError handlers.
These functions run at the position of this RouteHandler in the pipeline, meaning compression and security middleware that wraps this http.Handler will still be executed.
func (RouteHandler) HandleInternalServerError ¶
func (r RouteHandler) HandleInternalServerError(i interface{}) http.Handler
func (RouteHandler) HandleNotFound ¶
func (r RouteHandler) HandleNotFound(rq *http.Request) http.Handler
func (RouteHandler) ServeHTTP ¶
func (s RouteHandler) ServeHTTP(rw http.ResponseWriter, rq *http.Request)
ServeHTTP traverses this RouteHandler's Router tree. If a failure is encountered, if RouteHandler.Failure is non-nil, it is called for an http.Handler which it uses to handle the response, Handling at this RouteHandler's position in the middleware stack. If it is nil, ServeHTTP instead panics with an ExtendedErr.
type Router ¶
A Router value is used to find the correct http.Handler for this http.Request.
The routing terminates when Router is Handler, or if Router is nil.
func PathRouteHTTP ¶
func PathRouteHTTP(p PathingRouter, rq *http.Request) Router
Performs RouteHTTP on a trie of PathingRouters.
type RouterFunc ¶
type Subdomain ¶
Subdomain implements the DomainRouter interface and is used to route requests to subdomain trees and the paths below them.
The empty subdomain ("") is used when the route terminates here.