Documentation ¶
Overview ¶
Package response contains helpers for rendering HTTP responses.
Index ¶
- Variables
- func Init(d bool)
- func IsNotFoundError(err error) bool
- func Upgrade(hijackedConn net.Conn, protocolName string) error
- type FileResponseEntry
- type Response
- func BadRequest(err error) Response
- func Conflict(err error) Response
- func DevIncusErrorResponse(err error, rawResponse bool) Response
- func DevIncusResponse(code int, content any, contentType string, rawResponse bool) Response
- func ErrorResponse(code int, msg string) Response
- func FileResponse(r *http.Request, files []FileResponseEntry, headers map[string]string) Response
- func Forbidden(err error) Response
- func ForwardedResponse(client incus.InstanceServer, request *http.Request) 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 SmartError(err error) Response
- func SyncResponse(success bool, metadata any) Response
- func SyncResponseETag(success bool, metadata any, etag any) Response
- func SyncResponseHeaders(success bool, metadata any, headers map[string]string) Response
- func SyncResponseLocation(success bool, metadata any, location string) Response
- func SyncResponsePlain(success bool, compress bool, metadata string) Response
- func SyncResponseRedirect(address 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 IsNotFoundError ¶
IsNotFoundError returns true if the error is considered a Not Found error.
Types ¶
type FileResponseEntry ¶
type FileResponseEntry struct { // Required. Identifier string Filename string // Read from a filesystem path. Path string // Read from a file. File io.ReadSeeker FileSize int64 FileModified time.Time // Optional. Cleanup func() }
FileResponseEntry represents a file response entry.
type Response ¶
type Response interface { Render(w http.ResponseWriter) error String() string }
Response represents an API response.
func BadRequest ¶
BadRequest returns a bad request response (400) with the given error.
func DevIncusErrorResponse ¶
DevIncusErrorResponse returns an error response. If rawResponse is true, a api.ResponseRaw will be sent instead of a minimal devIncusResponse.
func DevIncusResponse ¶
DevIncusResponse represents a devIncusResponse. If rawResponse is true, a api.ResponseRaw will be sent instead of a minimal devIncusResponse.
func ErrorResponse ¶
ErrorResponse returns an error response with the given code and msg.
func FileResponse ¶
FileResponse returns a new file response.
func ForwardedResponse ¶
ForwardedResponse takes a request directed to a node and forwards it to another node, writing back the response it gegs.
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 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 SyncResponseETag ¶
SyncResponseETag returns a new syncResponse with an etag.
func SyncResponseHeaders ¶
SyncResponseHeaders returns a new syncResponse with headers.
func SyncResponseLocation ¶
SyncResponseLocation returns a new syncResponse with a location.
func SyncResponsePlain ¶
SyncResponsePlain return a new syncResponse with plaintext.
func SyncResponseRedirect ¶
SyncResponseRedirect returns a new syncResponse with a location, indicating a permanent redirect.
func Unauthorized ¶
Unauthorized return an unauthorized response (401) with the given error.
func Unavailable ¶
Unavailable return an unavailable response (503) with the given error.