respond

package
v0.0.0-...-ccf4274 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultResponder = Responder{}

DefaultResponder is a default Responder.

Functions

func ErrWithInfo

func ErrWithInfo(err error, info interface{}) errWithInfo

func WithCodedError

func WithCodedError(ctx context.Context, log logrus.FieldLogger, w http.ResponseWriter, r *http.Request, httpStatus int, code string, err error)

WithCodedError is a shortcut for DefaultResponder.WithCodedError.

func WithError

func WithError(ctx context.Context, log logrus.FieldLogger, w http.ResponseWriter, r *http.Request, httpStatus int, err error)

WithError is a shortcut for DefaultResponder.WithError.

func WithSuccess

func WithSuccess(ctx context.Context, log logrus.FieldLogger, w http.ResponseWriter, r *http.Request, httpStatus int, v interface{})

WithSuccess is a shortcut for DefaultResponder.WithSuccess.

Types

type ErrorInfoer

type ErrorInfoer interface {
	error
	ErrorInfo() interface{}
}

ErrorInfoer is an optional interface that errors can optionally implement to provide additional context in an error response.

type Responder

type Responder struct {
	SuppressErrors bool
}

Responder is a set of config for responding to requests.

func (Responder) WithCodedError

func (re Responder) WithCodedError(ctx context.Context, log logrus.FieldLogger, w http.ResponseWriter, r *http.Request, httpStatus int, code string, err error)

WithCodedError writes the provided error to the ResponseWriter, as well as the HTTP status code. An enum-style code (i.e. INVALID_TOKEN) may also be provided.

func (Responder) WithError

func (re Responder) WithError(ctx context.Context, log logrus.FieldLogger, w http.ResponseWriter, r *http.Request, httpStatus int, err error)

WithError is a shortcut for WithCodedError(ctx, log, w, httpStatus, "", err).

func (Responder) WithSuccess

func (re Responder) WithSuccess(ctx context.Context, log logrus.FieldLogger, w http.ResponseWriter, r *http.Request, httpStatus int, v interface{})

WithSuccess writes the provided response to the ResponseWriter (unwrapped) and sets the provided HTTP response status.

Jump to

Keyboard shortcuts

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