handler

package
v0.4.5 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2025 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

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,
	jsonDecoder gonethttpjson.Decoder,
) (*DefaultHandler, error)

NewDefaultHandler creates a new default request handler

func (*DefaultHandler) HandleErrorProneResponse

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

HandleErrorProneResponse handles the response that may contain an error

func (*DefaultHandler) HandleRequest

func (d *DefaultHandler) HandleRequest(
	w http.ResponseWriter,
	r *http.Request,
	data interface{},
) (err error)

HandleRequest handles the request

func (*DefaultHandler) HandleResponse added in v0.4.4

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

HandleResponse handles the response

type Handler

type Handler interface {
	HandleRequest(
		w http.ResponseWriter,
		r *http.Request,
		data interface{},
	) (err error)
	HandleResponse(w http.ResponseWriter, response *Response)
	HandleErrorProneResponse(
		w http.ResponseWriter,
		successResponse *Response,
		errorResponse *Response,
	)
}

Handler interface for handling the responses

type JSONErrorResponse

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

JSONErrorResponse struct

func NewJSONErrorResponse

func NewJSONErrorResponse(err error) JSONErrorResponse

NewJSONErrorResponse creates a new error response

type Response

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

Response struct

func NewDebugErrorResponse added in v0.4.4

func NewDebugErrorResponse(err error, debugErr error) *Response

NewDebugErrorResponse creates a new error response

func NewDebugErrorResponseWithCode added in v0.4.4

func NewDebugErrorResponseWithCode(
	err error,
	debugErr error,
	code int,
) *Response

NewDebugErrorResponseWithCode creates a new error response with a code

func NewDebugResponse added in v0.4.4

func NewDebugResponse(data interface{}, debugData interface{}) *Response

NewDebugResponse creates a new response

func NewDebugResponseWithCode added in v0.4.4

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

NewDebugResponseWithCode creates a new response with a code

func NewErrorResponse

func NewErrorResponse(err error) *Response

NewErrorResponse creates a new error response

func NewErrorResponseWithCode

func NewErrorResponseWithCode(err error, code int) *Response

NewErrorResponseWithCode creates a new error response with a code

func NewResponse

func NewResponse(data interface{}) *Response

NewResponse creates a new response

func NewResponseWithCode

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