httpresponse

package
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2025 License: Apache-2.0 Imports: 8 Imported by: 4

Documentation

Index

Constants

View Source
const (
	ErrBadRequest     = Err(http.StatusBadRequest)
	ErrNotFound       = Err(http.StatusNotFound)
	ErrConflict       = Err(http.StatusConflict)
	ErrNotImplemented = Err(http.StatusNotImplemented)
	ErrInternalError  = Err(http.StatusInternalServerError)
)

Variables

This section is empty.

Functions

func Attachment added in v1.5.0

func Attachment(w http.ResponseWriter, r io.Reader, code int, params map[string]string) error

Attachment will write out an attachment from a io.Reader

func Cors added in v1.4.11

func Cors(w http.ResponseWriter, r *http.Request, origin string, methods ...string)

Write the cors headers

func Empty

func Empty(w http.ResponseWriter, code int) error

Empty is a utility function to serve an empty response

func Error

func Error(w http.ResponseWriter, err error, detail ...any) error

Error writes an error from a HTTP status code, with additional detail

func JSON

func JSON(w http.ResponseWriter, code, indent int, v any) error

JSON will write a JSON response to the writer with a HTTP status code, optionally indenting the JSON by a number of spaces

Types

type Err added in v1.5.0

type Err int

Err turns a HTTP status code into an error

func (Err) Error added in v1.5.0

func (code Err) Error() string

func (Err) With added in v1.5.0

func (code Err) With(args ...interface{}) error

func (Err) Withf added in v1.5.0

func (code Err) Withf(format string, args ...interface{}) error

Jump to

Keyboard shortcuts

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