handlers

package
v0.0.0-...-bfe46a2 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2024 License: MPL-2.0 Imports: 11 Imported by: 12

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HealthCheckHandler

func HealthCheckHandler(version, buildTime, commit string, serviceStatus map[string]interface{}, check func() error) http.HandlerFunc

HealthCheckHandler - function which generates a health check http.HandlerFunc

Types

type AppError

type AppError struct {
	Cause     error       `json:"-"`
	Message   string      `json:"message"`             // description of failure
	ErrorCode string      `json:"errorCode,omitempty"` // short error code string
	Code      int         `json:"code"`                // status code for some reason
	Data      interface{} `json:"data,omitempty"`      // application specific data
}

AppError is error type for json HTTP responses

func RenderContent

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

RenderContent based on the header

func ValidationError

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 / responses

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

type HealthCheckResponse struct {
	Data HealthCheckResponseData `json:"data"`
}

HealthCheckResponse - response structure for healthchecks

type HealthCheckResponseData

type HealthCheckResponseData struct {
	BuildTime string `json:"buildTime"`
	Commit    string `json:"commit"`
	Version   string `json:"version"`
	// service status is an accumulated map of service health structures mapped on service name
	ServiceStatus map[string]interface{} `json:"serviceStatus,omitempty"`
}

HealthCheckResponseData - response structure for healthchecks

Jump to

Keyboard shortcuts

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