Documentation ¶
Overview ¶
Package alien is a lightweight http router from outer space.
Index ¶
- func ParseParams(matched, pattern string) (result string, err error)
- type Mux
- func (m *Mux) AddRoute(method, pattern string, h func(http.ResponseWriter, *http.Request)) error
- func (m *Mux) Connect(path string, h func(http.ResponseWriter, *http.Request)) error
- func (m *Mux) Delete(path string, h func(http.ResponseWriter, *http.Request)) error
- func (m *Mux) Get(pattern string, h func(http.ResponseWriter, *http.Request)) error
- func (m *Mux) Group(pattern string) *Mux
- func (m *Mux) Head(path string, h func(http.ResponseWriter, *http.Request)) error
- func (m *Mux) NotFoundHandler(h http.Handler)
- func (m *Mux) Options(path string, h func(http.ResponseWriter, *http.Request)) error
- func (m *Mux) Patch(path string, h func(http.ResponseWriter, *http.Request)) error
- func (m *Mux) Post(path string, h func(http.ResponseWriter, *http.Request)) error
- func (m *Mux) Put(path string, h func(http.ResponseWriter, *http.Request)) error
- func (m *Mux) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (m *Mux) Trace(path string, h func(http.ResponseWriter, *http.Request)) error
- func (m *Mux) Use(middleware ...func(http.Handler) http.Handler)
- type Params
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ParseParams ¶
ParseParams parses params found in mateched from pattern. There are two kinds of params, one to capture a segment which starts with : and a nother to capture everything( a.k.a catch all) whis starts with *.
For instance
pattern:="/hello/:name" matched:="/hello/world"
Will result into name:world. this function captures the named params and theri coreesponding values, returning them in a comma separated string of a key:value nature. please see the tests for more details.
Types ¶
type Mux ¶
type Mux struct {
// contains filtered or unexported fields
}
Mux is a http multiplexer that allows matching of http requests to the registered http handlers.
Mux supports named parameters in urls like
/hello/:name
will match
/hello/world
where by inside the request passed to the handler, the param with key name and value world will be passed.
Mux supports catch all parameters too
/hello/*whatever
will match
/hello/world /hello/world/tanzania /hello/world/afica/tanzania.png
where by inside the request passed to the handler, the param with key whatever will be set and value will be
world world/tanzania world/afica/tanzania.png
If you dont specify a name in a catch all route, then the default name "catch" will be ussed.
func New ¶
func New() *Mux
New returns a new *Mux instance with default handler for mismatched routes.
func (*Mux) AddRoute ¶
AddRoute registers h with pattern and method. If there is a path prefix created via the Group method) it will be set.
func (*Mux) Group ¶
Group creates a path prefix group for pattern, all routes registered using the returned Mux will only match if the request path starts with pattern. For instance .
m:=New() home:=m.Group("/home") home.Get("/alone",myHandler)
will match
/home/alone
func (*Mux) NotFoundHandler ¶
NotFoundHandler is executed when the request route is not found.
func (*Mux) ServeHTTP ¶
func (m *Mux) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP implements http.Handler interface. It muliplexes http requests against registered handlers.