Documentation ¶
Overview ¶
Package mux implements request routers.
Example ¶
http.Handle("/items", Method{ "GET": Accept{ "application/xml": XmlGetItemsHandler, "application/json": JsonGetItemsHandler, }, "POST": ContentType{ "application/xml": XmlAddItemsHandler, "application/json": JsonAddItemsHandler, }, "PUT": ContentType{ "application/xml": XmlEditItemsHandler, "application/json": JsonEditItemsHandler, }, })
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Accept ¶
Accept maps Accept header values to different handlers. This will attempt to match the acceptable content type with the highest requested quality and greatest specificity. A fallback of */* can be specified which will always match if no others do, otherwise a 406 Not Acceptable response is returned.
Example ¶
http.Handle("/items", Accept{ "application/xml": XmlItemsHandler, "application/json": JsonItemsHandler, })
Output:
type ContentType ¶
ContentType maps media-types to different handlers. Keys can contain wildcards, so application/* will be routed to for application/xml, application/json, etc. but only if there is no specific match. You can also define */* as a fallback handler, otherwise when no match is found a 415 Unsupported Media Type response is returned.
Example ¶
http.Handle("/items", ContentType{ "application/xml": XmlItemsHandler, "application/json": JsonItemsHandler, })
Output:
func (ContentType) ServeHTTP ¶
func (route ContentType) ServeHTTP(w http.ResponseWriter, r *http.Request)