handlers

package
v0.0.0-...-73aec22 Latest Latest
Warning

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

Go to latest
Published: May 20, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMethodNotAllowed = &ErrorResponse{StatusCode: http.StatusMethodNotAllowed, Message: "Method not allowed"}
	ErrNotFound         = &ErrorResponse{StatusCode: http.StatusNotFound, Message: "Resource not found"}
	ErrBadRequest       = &ErrorResponse{StatusCode: http.StatusBadRequest, Message: "Bad request"}
)

Functions

func ItemContext

func ItemContext(next http.Handler) http.Handler

ItemContext extracts the item ID from request

func NewHandler

func NewHandler(db db.Database) http.Handler

Types

type ErrorResponse

type ErrorResponse struct {
	Err        error  `json:"-"`
	StatusCode int    `json:"-"`
	StatusText string `json:"status_text"`
	Message    string `json:"message"`
}

ErrorResponse structures the error response in the API

func ErrorRenderer

func ErrorRenderer(err error) *ErrorResponse

ErrorRenderer handles rendering of Bad Request errors

func ServerErrorRenderer

func ServerErrorRenderer(err error) *ErrorResponse

ServerErrorRenderer handles rendering of Internal Server errors

func (*ErrorResponse) Render

Render handles inserting status code to error response

Jump to

Keyboard shortcuts

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