Documentation ¶
Index ¶
- Constants
- Variables
- func GetHost(r *http.Request) string
- func GetIP(r *http.Request, proxied bool) string
- func SetVariables(r *http.Request, v Variables) *http.Request
- func SplitPath(path string) []string
- type HandleFunc
- type Handler
- type Middleware
- type Mux
- func (r *Mux) Any(path string, handler HandleFunc, name ...string) *Route
- func (r *Mux) Delete(path string, handler HandleFunc, name ...string) *Route
- func (r *Mux) Find(name string) *Route
- func (r *Mux) Get(path string, handler HandleFunc, name ...string) *Route
- func (r *Mux) Handle(method string, path string, handler HandleFunc, name ...string) *Route
- func (r *Mux) Head(path string, handler HandleFunc, name ...string) *Route
- func (r *Mux) Match(method string, path string) (*Route, Variables)
- func (r *Mux) NotFound(w http.ResponseWriter, req *http.Request)
- func (r *Mux) Options(path string, handler HandleFunc, name ...string) *Route
- func (r *Mux) Patch(path string, handler HandleFunc, name ...string) *Route
- func (r *Mux) Post(path string, handler HandleFunc, name ...string) *Route
- func (r *Mux) Put(path string, handler HandleFunc, name ...string) *Route
- func (r *Mux) RemoveByPath(path string)
- func (r *Mux) RemoveRoute(route *Route)
- func (r *Mux) ResetRoutes()
- func (r *Mux) ServeHTTP(w http.ResponseWriter, req *http.Request)
- func (r *Mux) Use(middleware ...Middleware)
- type PathInfo
- type PathPart
- type Route
- func (r *Route) Any(path string, handler HandleFunc, name ...string) *Route
- func (r *Route) Delete(path string, handler HandleFunc, name ...string) *Route
- func (r *Route) Find(names []string) (*Route, bool)
- func (r *Route) Get(path string, handler HandleFunc, name ...string) *Route
- func (r *Route) Handle(method string, path string, handler HandleFunc, name ...string) *Route
- func (r *Route) Head(path string, handler HandleFunc, name ...string) *Route
- func (r *Route) ID() int64
- func (r *Route) Match(method string, path []string) (*Route, bool, Variables)
- func (r *Route) Options(path string, handler HandleFunc, name ...string) *Route
- func (r *Route) Patch(path string, handler HandleFunc, name ...string) *Route
- func (r *Route) Post(path string, handler HandleFunc, name ...string) *Route
- func (r *Route) Put(path string, handler HandleFunc, name ...string) *Route
- func (r *Route) RemoveByPath(path string) bool
- func (r *Route) RemoveChild(child *Route)
- func (r *Route) ServeHTTP(w http.ResponseWriter, req *http.Request)
- func (r *Route) String() string
- type Variables
Constants ¶
const ( // A special method, which will not be returned by any request, but can be set on the route to allow any method to pass. ANY = "*" GET = "GET" // Equivalent to http.MethodGet POST = "POST" // Equivalent to http.MethodPost PUT = "PUT" // Equivalent to http.MethodPut DELETE = "DELETE" // Equivalent to http.MethodDelete HEAD = "HEAD" // Equivalent to http.MethodHead PATCH = "PATCH" // Equivalent to http.MethodPatch OPTIONS = "OPTIONS" // Equivalent to http.MethodOptions )
Variables ¶
var ( VARIABLE_DELIMS = []string{"<<", ">>"} URL_DELIM = "/" GLOB = "*" )
Global variables for use in the package.
These are exported so that they can be changed if needed.
Functions ¶
Types ¶
type HandleFunc ¶
type HandleFunc func(w http.ResponseWriter, req *http.Request)
type Middleware ¶
Middleware which will run before/after the HandleFunc.
type Mux ¶
type Mux struct { NotFoundHandler http.HandlerFunc // contains filtered or unexported fields }
The muxer.
func (*Mux) RemoveByPath ¶ added in v1.0.4
func (*Mux) RemoveRoute ¶ added in v1.0.4
func (*Mux) ResetRoutes ¶ added in v1.0.5
func (r *Mux) ResetRoutes()
func (*Mux) Use ¶
func (r *Mux) Use(middleware ...Middleware)
type PathInfo ¶
PathInfo contains information about a path.
It can be used to match a path, and retrieve variables from it.
func NewPathInfo ¶
NewPathInfo creates a new PathInfo object from a path string.
The path string can contain variables, which are defined by the text between the VARIABLE_DELIMS.
This function will panic if the GLOB is not the last part of the path.
func (*PathInfo) CopyAppend ¶
Copies the slice, and append appends the other path to the end of this path.
It will panic if the path on which this was called is a glob.
type Route ¶
type Route struct { Name string Method string Path *PathInfo Children []*Route HandleFunc HandleFunc Parent *Route ParentMux *Mux // contains filtered or unexported fields }
func (*Route) Delete ¶
func (r *Route) Delete(path string, handler HandleFunc, name ...string) *Route
func (*Route) Handle ¶
Handle adds a handler to the route.
It returns the route that was added so that it can be used to add children.
func (*Route) Options ¶
func (r *Route) Options(path string, handler HandleFunc, name ...string) *Route