Documentation ¶
Overview ¶
Package rest provides functions for simple REST handling
SPDX-License-Identifier: Apache-2.0
Package rest provides functions for simple REST handling ¶
SPDX-License-Identifier: Apache-2.0
Index ¶
Constants ¶
const ( NotFoundMsg = "Not Found" MethodNotAllowedMsg = "Method Not Allowed" )
const (
UUIDGroup = "([0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12})"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Handler ¶
type Handler interface {
ServeHTTP(w http.ResponseWriter, r *http.Request, urlParts []string)
}
Handler is a REST handler The only difference compared to http.Handler is en extra argument of regex matches for url parts, so that the handler doesn't to re-evaluate the same regex a second time to get those values.
type HandlerFunc ¶
type HandlerFunc func(w http.ResponseWriter, r *http.Request, urlParts []string)
HandlerFunc is an adapter func for Handler
func (HandlerFunc) ServeHTTP ¶
func (hf HandlerFunc) ServeHTTP(w http.ResponseWriter, r *http.Request, urlParts []string)
ServeHTTP is HandlerFunc adapter method
type ServeMux ¶
type ServeMux struct {
// contains filtered or unexported fields
}
A ServeMux handles REST requests by performing pattern matching that considers the method and URL, rather than just the URL alone like the http.ServeMux implementation. The zero value is ready to use.
func (*ServeMux) Handle ¶
Handle maps the given method and regex string to the given handler. The regex allows capturing path parts that are variable, like a UUID. The Handle can be called anytime, even while HTTP requests are being served.
func (*ServeMux) MustHandle ¶
MustHandle is a must version of Handle