happier

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2023 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Overview

Package happier contains http REST API errors that are compatible with horror handlers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Accepted

func Accepted(w http.ResponseWriter, r *http.Request) horror.Error

Accepted outputs empty payload to http client with http status accepted.

func Created

func Created(w http.ResponseWriter, r *http.Request, payload interface{}) horror.Error

Created outputs given payload to http client with http status created.

If json package fails to marshal given payload, Created returns internal server error.

func NoContent

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

NoContent outputs empty payload to http client with http status no content.

func OK

func OK(w http.ResponseWriter, r *http.Request, payload interface{}) horror.Error

OK outputs given payload to http client with http status OK.

If json package fails to marshal given payload, OK returns internal server error.

func SeeOther

func SeeOther(w http.ResponseWriter, r *http.Request, url string) horror.Error

SeeOther redirects replies to the request with a redirect to url with See Other http status.

Types

type Adapter

type Adapter struct {
	// contains filtered or unexported fields
}

Adapter adapts horror Handlers for usage with chi router, because it accepts only HandlerFuncs to its routing methods along `pattern`.

Use NewAdapter as constructor if you want to use Adapter.

func NewAdapter

func NewAdapter() *Adapter

NewAdapter is the only proper constructor for Adapter type.

func (*Adapter) WithError

func (a *Adapter) WithError(h horror.Handler) http.HandlerFunc

WithError wraps given horror Handler, adapts it and returns http.HandlerFunc that you can use with chi router.

type Factory

type Factory struct {
	// contains filtered or unexported fields
}

Factory contains method for declaring http oriented errors.

func Default

func Default() *Factory

Default returns default error factory not associated with any http request.

func FromContext

func FromContext(ctx context.Context) *Factory

FromContext returns factory that should be used only within given context range.

func FromRequest

func FromRequest(r *http.Request) *Factory

FromRequest returns factory that should be used only with given http request.

func (*Factory) BadRequest

func (f *Factory) BadRequest(err error, message string) horror.Error

BadRequest implements http bad request (400) error for horror.Error interface to use in long-season REST API.

func (*Factory) Conflict

func (f *Factory) Conflict(err error, message string) horror.Error

Conflict implements http conflict (409) error for horror.Error interface to use in long-season REST API.

func (*Factory) InternalServerError

func (f *Factory) InternalServerError(err error, message string) horror.Error

InternalServerError implements http internal server error (500) for horror.Error interface to use in long-season REST API.

func (*Factory) NotFound

func (f *Factory) NotFound(err error, message string) horror.Error

NotFound implements http NotFound (404) error for horror.Error interface to use in long-season REST API.

func (*Factory) Unauthorized

func (f *Factory) Unauthorized(err error, message string) horror.Error

Unauthorized implements http unauthorized (401) error for horror.Error interface to use in long-season REST API.

Jump to

Keyboard shortcuts

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