api

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode(r io.Reader, v interface{}) error

func Error

func Error(w http.ResponseWriter, r *http.Request, status int, err error)

Error writes a JSON error response to w with the error message in an "error" field:

api.Error(w, r, 404, errors.New("entity not found"))
// {"error": "entity not found"}

func ExtractUUID

func ExtractUUID(r *http.Request, name string) (uuid.UUID, error)

func Friendly

func Friendly(err error, format string, v ...interface{}) error

Friendly returns a FriendlyError that wraps err with the provided message.

func JSON

func JSON(w http.ResponseWriter, r *http.Request, status int, v interface{})

func NoContent

func NoContent(w http.ResponseWriter, r *http.Request)

func ParseUUID

func ParseUUID(raw, desc string) (uuid.UUID, error)

Types

type FriendlyError

type FriendlyError struct {
	Err     error
	Message string
}

FriendlyError is an error with a human-friendly message.

func (FriendlyError) Error

func (err FriendlyError) Error() string

func (FriendlyError) FriendlyError

func (err FriendlyError) FriendlyError() string

func (FriendlyError) Unwrap

func (err FriendlyError) Unwrap() error

Jump to

Keyboard shortcuts

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