Documentation
¶
Overview ¶
Package rest provides functions for simple REST handling
SPDX-License-Identifier: Apache-2.0
Index ¶
Constants ¶
const ( NotFoundMsg = "Not Found" MethodNotAllowedMsg = "Method Not Allowed" 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 ¶
func AcceptGzip ¶
AcceptGzip checks if the request Accept-Encoding header is gzip. If so, it returns a new io.Reader which decompresses the body io.Reader using gzip. Otherwise, it returns the body io.Reader as is.
func NegotiateCSVContent ¶
NegotiateCSVContent returns an Iter[[]string] if the Content-Type header is text/csv, otherwise it returns nil
Types ¶
type Handler ¶
type Handler interface {
Serve(w http.ResponseWriter, r *http.Request, urlParts []string)
}
Handler is a REST handler The only difference compared to http.Handler is an extra argument of regex matches for url parts, so that the handler doesn't have 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) Serve ¶
func (hf HandlerFunc) Serve(w http.ResponseWriter, r *http.Request, urlParts []string)
Serve 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. This method can be called any time, even while HTTP requests are being served.
func (*ServeMux) MustHandle ¶
MustHandle is a must version of Handle