Documentation
¶
Index ¶
- Variables
- func EtagCheck(r *http.Request, data any) error
- func EtagHash(data any) (string, error)
- func IsNotFoundError(err error) bool
- func With(handler HandlerFunc, middlewares ...func(next HandlerFunc) HandlerFunc) http.HandlerFunc
- type HandlerFunc
- type Response
- func BadRequest(err error) Response
- func Forbidden(err error) Response
- func InternalError(err error) Response
- func ManualResponse(hook func(w http.ResponseWriter) error) Response
- func NotFound(err error) Response
- func NotImplemented(err error) Response
- func PreconditionFailed(err error) Response
- func ReadCloserResponse(r *http.Request, rc io.ReadCloser, compress bool, filename string, ...) Response
- func SmartError(err error) Response
- func SyncResponse(success bool, metadata any) Response
- func SyncResponseETag(success bool, metadata any, etag any) Response
- func SyncResponseLocation(success bool, metadata any, location string) Response
- func SyncResponsePlain(success bool, compress bool, metadata string) Response
- func Unauthorized(err error) Response
- func Unavailable(err error) Response
Constants ¶
This section is empty.
Variables ¶
var EmptySyncResponse = &syncResponse{success: true, metadata: make(map[string]any)}
EmptySyncResponse represents an empty syncResponse.
Functions ¶
func EtagCheck ¶
EtagCheck validates the hash of the current state with the hash provided by the client.
func IsNotFoundError ¶
IsNotFoundError returns true if the error is considered a Not Found error.
func With ¶
func With(handler HandlerFunc, middlewares ...func(next HandlerFunc) HandlerFunc) http.HandlerFunc
Types ¶
type HandlerFunc ¶
type Response ¶
type Response interface { Render(w http.ResponseWriter) error String() string Code() int }
Response represents an API response.
func BadRequest ¶
BadRequest returns a bad request response (400) with the given error.
func InternalError ¶
InternalError returns an internal error response (500) with the given error.
func ManualResponse ¶
func ManualResponse(hook func(w http.ResponseWriter) error) Response
ManualResponse creates a new manual response responder.
func NotImplemented ¶
NotImplemented returns a not implemented response (501) with the given error.
func PreconditionFailed ¶
PreconditionFailed returns a precondition failed response (412) with the given error.
func ReadCloserResponse ¶
func ReadCloserResponse(r *http.Request, rc io.ReadCloser, compress bool, filename string, fileSize int, headers map[string]string) Response
ReadCloserResponse returns a new file taking the file content from a io.ReadCloser. If the fileSize is unknown, -1 should be passed in order to omit the Content-Length HTTP header. If compress is set to true and the client provides the HTTP header "Accept-Encoding: gzip", the file is streamed with "Content-Encoding: gzip". If compress is set to true but the client does not offer "Content-Encoding: gzip", the file is returned as .gz file.
func SmartError ¶
SmartError returns the right error message based on err. It uses the stdlib errors package to unwrap the error and find the cause.
func SyncResponse ¶
SyncResponse returns a new syncResponse with the success and metadata fields set to the provided values.
func SyncResponseLocation ¶
SyncResponseLocation returns a new syncResponse with a location.
func SyncResponsePlain ¶
SyncResponsePlain return a new syncResponse with plaintext.
func Unauthorized ¶
Unauthorized return an unauthorized response (401) with the given error.
func Unavailable ¶
Unavailable return an unavailable response (503) with the given error.