resp

package
v0.0.0-...-00f2437 Latest Latest
Warning

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

Go to latest
Published: May 24, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrorResponder

type ErrorResponder struct {

	// Status is the HTTP status code to set when sending the error
	Status int

	// PublicError is the error to return to the user
	PublicError error

	// DetailError provides more details error information which will not be shown to the end user. Can be nil
	DetailError error
	// contains filtered or unexported fields
}

ErrorResponder implements the Responder interface by sending an error to the client

func NewErrorResponder

func NewErrorResponder(logger golog.Logger, status int, pubErr error, detErr error) ErrorResponder

NewErrorResponder creates an ErrorResponder

func NewStrErrorResponder

func NewStrErrorResponder(logger golog.Logger, status int, pubErrStr, detErrStr string) ErrorResponder

NewStrErrorResponder creates an ErrorResponder. An error for PublicError and DetailError will be created from the error string arguments.

func (ErrorResponder) Respond

func (e ErrorResponder) Respond(w http.ResponseWriter, r *http.Request)

Respond implements Responder.Respond

type JSONResponder

type JSONResponder struct {
	// Data is the JSON data to respond with
	Data interface{}

	// Status is the HTTP status code to respond with, defaults to 200
	Status int
}

JSONResponder implements the Responder interface by sending a JSON response to the client

func NewJSONResponder

func NewJSONResponder(data interface{}, status int) JSONResponder

NewJSONResponder creates a new JSONResponder

func (JSONResponder) Respond

func (r JSONResponder) Respond(w http.ResponseWriter, req *http.Request)

Respond implements Responder.Respond

type RedirectResponder

type RedirectResponder struct {
	// Location is the URL the client will be redirected to
	Location string

	// Permanent indicates if a redirect is permanent. If a redirect is permanent the 308 (permanent redirect) HTTP
	// status code is used. Otherwise the 307 (temporary redirect) status code is used.
	Permanent bool
}

RedirectResponder issues a redirect response

func NewRedirectResponder

func NewRedirectResponder(location string, permanent bool) RedirectResponder

NewRedirectResponder creates a RedirectResponder

func (RedirectResponder) Respond

func (r RedirectResponder) Respond(w http.ResponseWriter, req *http.Request)

Respond implements Responder.Respond

type Responder

type Responder interface {
	// Respond sends a response to an HTTP request
	Respond(w http.ResponseWriter, r *http.Request)
}

Responder provides an extendible way to respond to HTTP requests

type ResponderHandler

type ResponderHandler interface {
	// Handle handles an HTTP request and returns a Responder which will be used to respond to the HTTP request
	Handle(r *http.Request) Responder
}

ResponderHandler handles HTTP requests using a handler method which returns a Responder. This Responder can then be invoked by a standard http.Handler to respond to an HTTP request.

type ResponderHandlerWrapper

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

ResponderHandlerWrapper calls a ResponderHandler in its http.Handler.ServeHTTP method. So a ResponderHandler can be used as a standard http.Handler

func WrapResponderHandler

func WrapResponderHandler(responderHandler ResponderHandler) ResponderHandlerWrapper

WrapResponderHandler wraps a ResponderHandler in a ResponderHandlerWrapper so it can be called as a standard http.Handler

func (ResponderHandlerWrapper) ServeHTTP

func (wrapper ResponderHandlerWrapper) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements http.Handler.ServeHTTP

Jump to

Keyboard shortcuts

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