Documentation ¶
Index ¶
- Constants
- func GetAllQueries(req *http.Request) map[string][]string
- func GetAllValues(req *http.Request) map[string]string
- func GetQuery(req *http.Request, key string) []string
- func GetValue(req *http.Request, key string) string
- type Mux
- func (m *Mux) DefaultServe(rw http.ResponseWriter, req *http.Request)
- func (m *Mux) Delete(path string, handler http.Handler) *Route
- func (m *Mux) DeleteFunc(path string, handler http.HandlerFunc) *Route
- func (m *Mux) Get(path string, handler http.Handler) *Route
- func (m *Mux) GetFunc(path string, handler http.HandlerFunc) *Route
- func (m *Mux) GetRequestRoute(req *http.Request) string
- func (m *Mux) Handle(path string, handler http.Handler)
- func (m *Mux) HandleFunc(path string, handler http.HandlerFunc)
- func (m *Mux) HandleNotFound(rw http.ResponseWriter, req *http.Request)
- func (m *Mux) Head(path string, handler http.Handler) *Route
- func (m *Mux) HeadFunc(path string, handler http.HandlerFunc) *Route
- func (m *Mux) ListenAndServe(port string) error
- func (m *Mux) NotFound(handler http.Handler)
- func (m *Mux) NotFoundFunc(handler http.HandlerFunc)
- func (m *Mux) Options(path string, handler http.Handler) *Route
- func (m *Mux) OptionsFunc(path string, handler http.HandlerFunc) *Route
- func (m *Mux) Patch(path string, handler http.Handler) *Route
- func (m *Mux) PatchFunc(path string, handler http.HandlerFunc) *Route
- func (m *Mux) Post(path string, handler http.Handler) *Route
- func (m *Mux) PostFunc(path string, handler http.HandlerFunc) *Route
- func (m *Mux) Prefix(p string) *Mux
- func (m *Mux) Put(path string, handler http.Handler) *Route
- func (m *Mux) PutFunc(path string, handler http.HandlerFunc) *Route
- func (m *Mux) Register(method string, path string, handler http.Handler) *Route
- func (m *Mux) RegisterValidator(name string, validator Validator)
- func (m *Mux) RegisterValidatorFunc(name string, validator func(string) bool)
- func (m *Mux) ServeHTTP(rw http.ResponseWriter, req *http.Request)
- func (m *Mux) SubRoute(path string, router Router) *Route
- type Route
- func (r *Route) Delete() *Route
- func (r *Route) Get() *Route
- func (r *Route) Head() *Route
- func (r *Route) Match(req *http.Request) bool
- func (r *Route) Options() *Route
- func (r *Route) Patch() *Route
- func (r *Route) Post() *Route
- func (r *Route) Put() *Route
- func (r *Route) ServeHTTP(rw http.ResponseWriter, req *http.Request)
- type Router
- type Token
- type Validator
Constants ¶
const ( //PARAM value store in Atts if the route have parameters PARAM = 2 //SUB value store in Atts if the route is a sub router SUB = 4 //WC value store in Atts if the route have wildcard WC = 8 //REGEX value store in Atts if the route contains regex REGEX = 16 )
Variables ¶
This section is empty.
Functions ¶
func GetAllQueries ¶
GetAllQueries return all queries of the current *http.Request
func GetAllValues ¶
GetAllValues return the req PARAMs
Types ¶
type Mux ¶
type Mux struct { Routes map[string][]*Route Validators map[string]Validator Serve func(rw http.ResponseWriter, req *http.Request) CaseSensitive bool // contains filtered or unexported fields }
Mux have routes and a notFound handler Route: all the registred route notFound: 404 handler, default http.NotFound if not provided
func (*Mux) DefaultServe ¶
func (m *Mux) DefaultServe(rw http.ResponseWriter, req *http.Request)
DefaultServe is the default http request handler
func (*Mux) DeleteFunc ¶
func (m *Mux) DeleteFunc(path string, handler http.HandlerFunc) *Route
DeleteFunc add a new route to the Mux with the Delete method
func (*Mux) GetFunc ¶
func (m *Mux) GetFunc(path string, handler http.HandlerFunc) *Route
GetFunc add a new route to the Mux with the Get method
func (*Mux) GetRequestRoute ¶
GetRequestRoute returns the route of given Request
func (*Mux) HandleFunc ¶
func (m *Mux) HandleFunc(path string, handler http.HandlerFunc)
HandleFunc is use to pass a func(http.ResponseWriter, *Http.Request) instead of http.Handler
func (*Mux) HandleNotFound ¶
func (m *Mux) HandleNotFound(rw http.ResponseWriter, req *http.Request)
HandleNotFound handle when a request does not match a registered handler.
func (*Mux) HeadFunc ¶
func (m *Mux) HeadFunc(path string, handler http.HandlerFunc) *Route
HeadFunc add a new route to the Mux with the Head method
func (*Mux) NotFoundFunc ¶
func (m *Mux) NotFoundFunc(handler http.HandlerFunc)
NotFoundFunc the mux custom 404 handler
func (*Mux) OptionsFunc ¶
func (m *Mux) OptionsFunc(path string, handler http.HandlerFunc) *Route
OptionsFunc add a new route to the Mux with the Options method
func (*Mux) PatchFunc ¶
func (m *Mux) PatchFunc(path string, handler http.HandlerFunc) *Route
PatchFunc add a new route to the Mux with the Patch method
func (*Mux) PostFunc ¶
func (m *Mux) PostFunc(path string, handler http.HandlerFunc) *Route
PostFunc add a new route to the Mux with the Post method
func (*Mux) PutFunc ¶
func (m *Mux) PutFunc(path string, handler http.HandlerFunc) *Route
PutFunc add a new route to the Mux with the Put method
func (*Mux) RegisterValidator ¶
RegisterValidator makes the provided validator available to the routes register on that mux
func (*Mux) RegisterValidatorFunc ¶
RegisterValidatorFunc makes the provided function available to the routes register on that mux as a validator
type Route ¶
type Route struct { Path string Method string Size int Atts int Token Token Pattern map[int]string Compile map[int]*regexp.Regexp Tag map[int]string Handler http.Handler // contains filtered or unexported fields }
Route content the required information for a valid route Path: is the Route URL Size: is the length of the path Token: is the value of each part of the path, split by / Pattern: is content information about the route, if it's have a route variable handler: is the handler who handle this route Method: define HTTP method on the route
type Router ¶
type Router interface {
ServeHTTP(http.ResponseWriter, *http.Request)
}
Router is the same as a http.Handler