handlers

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2021 License: MPL-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HealthCheckHandler added in v0.3.0

func HealthCheckHandler(version, buildTime, commit string) http.HandlerFunc

HealthCheckHandler - function which generates a health check http.HandlerFunc

Types

type AppError

type AppError struct {
	Cause   error       `json:"-"`
	Message string      `json:"message"`
	Code    int         `json:"code"`
	Data    interface{} `json:"data,omitempty"`
}

AppError is error type for json HTTP responses

func RenderContent added in v0.3.0

func RenderContent(ctx context.Context, v interface{}, w http.ResponseWriter, status int) *AppError

RenderContent based on the header

func ValidationError added in v0.2.0

func ValidationError(message string, validationErrors interface{}) *AppError

ValidationError creates an error to communicate a bad request was formed

func WrapError

func WrapError(err error, msg string, passedCode int) *AppError

WrapError with an additional message as an AppError

func WrapValidationError

func WrapValidationError(err error) *AppError

WrapValidationError from govalidator

func (AppError) Error

func (e AppError) Error() string

Error makes app error an error

func (AppError) ServeHTTP

func (e AppError) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP responds according to the passed AppError

type AppHandler

type AppHandler func(http.ResponseWriter, *http.Request) *AppError

AppHandler is an http.Handler with JSON requests / reponses

func (AppHandler) ServeHTTP

func (fn AppHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP responds via the passed handler and handles returned errors

type HealthCheckResponse added in v0.3.0

type HealthCheckResponse struct {
	BuildTime string `json:"build_time"`
	Commit    string `json:"commit"`
	Version   string `json:"version"`
}

HealthCheckResponse - response structure for healthchecks

func (HealthCheckResponse) RenderJSON added in v0.3.0

RenderJSON - helper to render a HealthCheckResponse as Json to an http.ResponseWriter

Jump to

Keyboard shortcuts

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