response

package
v0.0.0-pre.4 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2025 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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

EmptySyncResponse represents an empty syncResponse.

Functions

func IsNotFoundError

func IsNotFoundError(err error) bool

IsNotFoundError returns true if the error is considered a Not Found error.

Types

type Response

type Response interface {
	Render(w http.ResponseWriter) error
	String() string
	Code() int
}

Response represents an API response.

func BadRequest

func BadRequest(err error) Response

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

func Forbidden

func Forbidden(err error) Response

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

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. It uses the stdlib errors package to unwrap the error and find the cause.

func SyncResponse

func SyncResponse(success bool, metadata any) Response

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

func SyncResponseETag

func SyncResponseETag(success bool, metadata any, etag any) Response

SyncResponseETag returns a new syncResponse with an etag.

func SyncResponseLocation

func SyncResponseLocation(success bool, metadata any, location string) Response

SyncResponseLocation returns a new syncResponse with a location.

func Unauthorized

func Unauthorized(err error) Response

Unauthorized return an unauthorized response (401) with the given error.

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