Documentation
¶
Index ¶
- Variables
- func ErrWithInfo(err error, info interface{}) errWithInfo
- func WithCodedError(ctx context.Context, log logrus.FieldLogger, w http.ResponseWriter, ...)
- func WithError(ctx context.Context, log logrus.FieldLogger, w http.ResponseWriter, ...)
- func WithSuccess(ctx context.Context, log logrus.FieldLogger, w http.ResponseWriter, ...)
- type ErrorInfoer
- type Responder
- func (re Responder) WithCodedError(ctx context.Context, log logrus.FieldLogger, w http.ResponseWriter, ...)
- func (re Responder) WithError(ctx context.Context, log logrus.FieldLogger, w http.ResponseWriter, ...)
- func (re Responder) WithSuccess(ctx context.Context, log logrus.FieldLogger, w http.ResponseWriter, ...)
Constants ¶
This section is empty.
Variables ¶
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.