response

package
v0.0.0-...-b84de06 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 9, 2020 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var EmptySyncResponse = &syncResponse{success: true, metadata: make(map[string]interface{})}

EmptySyncResponse represents an empty syncResponse.

Functions

func Init

func Init(d bool)

Init sets the debug variable to the provided value.

Types

type FileResponseEntry

type FileResponseEntry struct {
	Identifier string
	Path       string
	Filename   string
	Buffer     []byte /* either a path or a buffer must be provided */
}

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

func BadRequest(err error) Response

BadRequest returns a bad request response (400) with the given error.

func Conflict

func Conflict(err error) Response

Conflict returns a conflict response (409) with the given error.

func ErrorResponse

func ErrorResponse(code int, msg string) Response

ErrorResponse returns an error response with the given code and msg.

func FileResponse

func FileResponse(r *http.Request, files []FileResponseEntry, headers map[string]string, removeAfterServe bool) Response

FileResponse returns a new file response.

func Forbidden

func Forbidden(err error) Response

Forbidden returns a forbidden response (403) with the given error.

func ForwardedResponse

func ForwardedResponse(client lxd.InstanceServer, request *http.Request) Response

ForwardedResponse takes a request directed to a node and forwards it to another node, writing back the response it gegs.

func InternalError

func InternalError(err error) Response

InternalError returns an internal error response (500) with the given error.

func NotFound

func NotFound(err error) Response

NotFound returns a not found response (404) with the given error.

func NotImplemented

func NotImplemented(err error) Response

NotImplemented returns a not implemented response (501) with the given error.

func PreconditionFailed

func PreconditionFailed(err error) Response

PreconditionFailed returns a precondition failed response (412) with the given error.

func SmartError

func SmartError(err error) Response

SmartError returns the right error message based on err.

func SyncResponse

func SyncResponse(success bool, metadata interface{}) Response

SyncResponse returns a new syncResponse with the success and metadata fields set to the provided values.

func SyncResponseETag

func SyncResponseETag(success bool, metadata interface{}, etag interface{}) Response

SyncResponseETag returns a new syncResponse with an etag.

func SyncResponseHeaders

func SyncResponseHeaders(success bool, metadata interface{}, headers map[string]string) Response

SyncResponseHeaders returns a new syncResponse with headers.

func SyncResponseLocation

func SyncResponseLocation(success bool, metadata interface{}, location string) Response

SyncResponseLocation returns a new syncResponse with a location.

func SyncResponseRedirect

func SyncResponseRedirect(address string) Response

SyncResponseRedirect returns a new syncResponse with a location, indicating a permanent redirect.

func Unavailable

func Unavailable(err error) Response

Unavailable return an unavailable response (503) with the given error.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL