handlers

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package handlers contains custom handler functions

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidInput is returned when the input is invalid
	ErrInvalidInput = errors.New("invalid input")

	// ErrConflict is returned when the request cannot be processed due to a conflict
	ErrConflict = errors.New("conflict")
)
View Source
var (
	// InvalidInputErrCode is returned when the input is invalid
	InvalidInputErrCode rout.ErrorCode = "INVALID_INPUT"
)

Functions

This section is empty.

Types

type CheckFunc

type CheckFunc func(ctx context.Context) error

CheckFunc is a function that can be used to check the status of a service

type Checks

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

func (*Checks) ReadyHandler

func (c *Checks) ReadyHandler(ctx echo.Context) error

type Handler

type Handler struct {
	// IsTest is a flag to determine if the application is running in test mode and will mock external calls
	IsTest bool
	// Logger provides the zap logger to do logging things from the handlers
	Logger *zap.SugaredLogger
	// ReadyChecks is a set of checkFuncs to determine if the application is "ready" upon startup
	ReadyChecks Checks
	// DatumClient is the client to interact with the Datum API
	DatumClient *datumclient.DatumClient
}

Handler contains configuration options for handlers

func (*Handler) AddReadinessCheck

func (h *Handler) AddReadinessCheck(name string, f CheckFunc)

AddReadinessCheck will accept a function to be ran during calls to /readyz These functions should accept a context and only return an error. When adding a readiness check a name is also provided, this name will be used when returning the state of all the checks

func (*Handler) AddRequestBody

func (h *Handler) AddRequestBody(name string, body interface{}, op *openapi3.Operation)

AddRequestBody is used to add a request body definition to the OpenAPI schema

func (*Handler) AddResponse

func (h *Handler) AddResponse(name string, description string, body interface{}, op *openapi3.Operation, status int)

AddResponse is used to add a response definition to the OpenAPI schema

func (*Handler) BadRequest

func (h *Handler) BadRequest(ctx echo.Context, err error) error

BadRequest returns a 400 Bad Request response with the error message.

func (*Handler) BadRequestWithCode

func (h *Handler) BadRequestWithCode(ctx echo.Context, err error, code rout.ErrorCode) error

BadRequest returns a 400 Bad Request response with the error message.

func (*Handler) BindWorkspaceHandler

func (h *Handler) BindWorkspaceHandler() *openapi3.Operation

BindWorkspaceHandler is used to bind the workspace endpoint to the OpenAPI schema

func (*Handler) Conflict

func (h *Handler) Conflict(ctx echo.Context, err string, code rout.ErrorCode) error

Conflict returns a 409 Conflict response with the error message.

func (*Handler) Created

func (h *Handler) Created(ctx echo.Context, rep interface{}) error

Created returns a 201 Created response with the response object.

func (*Handler) InternalServerError

func (h *Handler) InternalServerError(ctx echo.Context, err error) error

InternalServerError returns a 500 Internal Server Error response with the error message.

func (*Handler) InvalidInput

func (h *Handler) InvalidInput(ctx echo.Context, err error) error

InvalidInput returns a 400 Bad Request response with the error message.

func (*Handler) NotFound

func (h *Handler) NotFound(ctx echo.Context, err error) error

NotFound returns a 404 Not Found response with the error message.

func (*Handler) Success

func (h *Handler) Success(ctx echo.Context, rep interface{}) error

Success returns a 200 OK response with the response object.

func (*Handler) TooManyRequests

func (h *Handler) TooManyRequests(ctx echo.Context, err error) error

TooManyRequests returns a 429 Too Many Requests response with the error message.

func (*Handler) Unauthorized

func (h *Handler) Unauthorized(ctx echo.Context, err error) error

Unauthorized returns a 401 Unauthorized response with the error message.

func (*Handler) WorkspaceHandler

func (h *Handler) WorkspaceHandler(ctx echo.Context) error

WorkspaceHandler is the handler for the workspace endpoint

type StatusReply

type StatusReply struct {
	Status map[string]string `json:"status"`
}

StatusReply returns server status

Jump to

Keyboard shortcuts

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