response

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2024 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNilHandler = errors.New("response handler cannot be nil")
)

Functions

func SendInternalServerError added in v0.3.2

func SendInternalServerError(w http.ResponseWriter)

SendInternalServerError sends an internal server error response

Types

type DefaultHandler

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

DefaultHandler struct

func NewDefaultHandler

func NewDefaultHandler(
	mode *goflagsmode.Flag,
	jsonEncoder gonethttpjson.Encoder,
) (*DefaultHandler, error)

NewDefaultHandler creates a new default request handler

func (*DefaultHandler) HandleError added in v0.3.0

func (d *DefaultHandler) HandleError(
	w http.ResponseWriter,
	response *Response,
)

HandleError handles the error response

func (*DefaultHandler) HandleErrorProne added in v0.3.0

func (d *DefaultHandler) HandleErrorProne(
	w http.ResponseWriter,
	successResponse *Response,
	errorResponse *Response,
)

HandleErrorProne handles the response that may contain an error

func (*DefaultHandler) HandleSuccess added in v0.3.0

func (d *DefaultHandler) HandleSuccess(
	w http.ResponseWriter,
	response *Response,
)

HandleSuccess handles the response

type Handler

type Handler interface {
	HandleSuccess(w http.ResponseWriter, response *Response)
	HandleErrorProne(
		w http.ResponseWriter,
		successResponse *Response,
		errorResponse *Response,
	)
	HandleError(w http.ResponseWriter, response *Response)
}

Handler interface for handling the responses

type JSONErrorResponse added in v0.3.0

type JSONErrorResponse struct {
	Error string `json:"error"`
}

JSONErrorResponse struct

func NewJSONErrorResponse added in v0.3.0

func NewJSONErrorResponse(err error) JSONErrorResponse

NewJSONErrorResponse creates a new error response

type Response added in v0.3.0

type Response struct {
	Data interface{}
	Code *int
}

Response struct

func NewErrorResponse

func NewErrorResponse(err error) *Response

NewErrorResponse creates a new error response

func NewErrorResponseWithCode added in v0.3.0

func NewErrorResponseWithCode(err error, code int) *Response

NewErrorResponseWithCode creates a new error response with a code

func NewResponse added in v0.3.0

func NewResponse(data interface{}) *Response

NewResponse creates a new response

func NewResponseWithCode added in v0.3.0

func NewResponseWithCode(data interface{}, code int) *Response

NewResponseWithCode creates a new response with a code

Jump to

Keyboard shortcuts

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