Documentation ¶
Overview ¶
Package routes a simple http routing API for the Go programming language, compatible with the standard http.ListenAndServe function.
Create a new route multiplexer:
mux := routes.New()
Define a simple route with a given method (ie Get, Put, Post ...), path and http.HandleFunc.
mux.Get("/foo", fooHandler)
Define a route with restful parameters in the path:
mux.Get("/:foo/:bar", func(w http.ResponseWriter, r *http.Request) { params := r.URL.Query() foo := params.Get(":foo") bar := params.Get(":bar") fmt.Fprintf(w, "%s %s", foo, bar) })
The parameters are parsed from the URL, and appended to the Request URL's query parameters.
More control over the route's parameter matching is possible by providing a custom regular expression:
mux.Get("/files/:file(.+)", handler)
To start the web server, use the standard http.ListenAndServe function, and provide the route multiplexer:
http.Handle("/", mux) http.ListenAndServe(":8000", nil)
Index ¶
- Constants
- func ReadJson(r *http.Request, v interface{}) error
- func ReadXml(r *http.Request, v interface{}) error
- func ServeFormatted(w http.ResponseWriter, r *http.Request, v interface{})
- func ServeJSONEncode(w http.ResponseWriter, r *http.Request, v interface{})
- func ServeJson(w http.ResponseWriter, v interface{})
- func ServeXml(w http.ResponseWriter, v interface{})
- type AcceptEncoding
- type RouteMux
- func (m *RouteMux) AddRoute(method string, pattern string, handler http.HandlerFunc)
- func (m *RouteMux) Del(pattern string, handler http.HandlerFunc)
- func (m *RouteMux) Delete(pattern string, handler http.HandlerFunc)
- func (m *RouteMux) Filter(filter http.HandlerFunc)
- func (m *RouteMux) FilterParam(param string, filter http.HandlerFunc)
- func (m *RouteMux) Get(pattern string, handler http.HandlerFunc)
- func (m *RouteMux) Patch(pattern string, handler http.HandlerFunc)
- func (m *RouteMux) Post(pattern string, handler http.HandlerFunc)
- func (m *RouteMux) Put(pattern string, handler http.HandlerFunc)
- func (m *RouteMux) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (m *RouteMux) Static(pattern string, dir string)
Constants ¶
const ( CONNECT = "CONNECT" DELETE = "DELETE" GET = "GET" HEAD = "HEAD" OPTIONS = "OPTIONS" PATCH = "PATCH" POST = "POST" PUT = "PUT" TRACE = "TRACE" )
Variables ¶
This section is empty.
Functions ¶
func ReadJson ¶
ReadJson will parses the JSON-encoded data in the http Request object and stores the result in the value pointed to by v.
func ReadXml ¶
ReadXml will parses the XML-encoded data in the http Request object and stores the result in the value pointed to by v.
func ServeFormatted ¶
func ServeFormatted(w http.ResponseWriter, r *http.Request, v interface{})
ServeFormatted replies to the request with a formatted representation of resource v, in the format requested by the client specified in the Accept header.
func ServeJSONEncode ¶
func ServeJSONEncode(w http.ResponseWriter, r *http.Request, v interface{})
ServeJSONEncode is eager JSON writer with gzip encoding where possible
func ServeJson ¶
func ServeJson(w http.ResponseWriter, v interface{})
ServeJson replies to the request with a JSON representation of resource v.
func ServeXml ¶
func ServeXml(w http.ResponseWriter, v interface{})
ServeXml replies to the request with an XML representation of resource v.
Types ¶
type RouteMux ¶
type RouteMux struct {
// contains filtered or unexported fields
}
func (*RouteMux) AddRoute ¶
func (m *RouteMux) AddRoute(method string, pattern string, handler http.HandlerFunc)
Adds a new Route to the Handler
func (*RouteMux) Del ¶
func (m *RouteMux) Del(pattern string, handler http.HandlerFunc)
Del adds a new Route for DELETE requests.
func (*RouteMux) Delete ¶
func (m *RouteMux) Delete(pattern string, handler http.HandlerFunc)
Delete is same as Del but created for compatibility
func (*RouteMux) Filter ¶
func (m *RouteMux) Filter(filter http.HandlerFunc)
Filter adds the middleware filter.
func (*RouteMux) FilterParam ¶
func (m *RouteMux) FilterParam(param string, filter http.HandlerFunc)
FilterParam adds the middleware filter iff the REST URL parameter exists.
func (*RouteMux) Get ¶
func (m *RouteMux) Get(pattern string, handler http.HandlerFunc)
Get adds a new Route for GET requests.
func (*RouteMux) Patch ¶
func (m *RouteMux) Patch(pattern string, handler http.HandlerFunc)
Patch adds a new Route for PATCH requests.
func (*RouteMux) Post ¶
func (m *RouteMux) Post(pattern string, handler http.HandlerFunc)
Post adds a new Route for POST requests.
func (*RouteMux) Put ¶
func (m *RouteMux) Put(pattern string, handler http.HandlerFunc)
Put adds a new Route for PUT requests.
Directories ¶
Path | Synopsis |
---|---|
exp
|
|
cookie/authcookie
Package authcookie implements creation and verification of signed authentication cookies.
|
Package authcookie implements creation and verification of signed authentication cookies. |
routes
Package routes a simple http routing API for the Go programming language, compatible with the standard http.ListenAndServe function.
|
Package routes a simple http routing API for the Go programming language, compatible with the standard http.ListenAndServe function. |