handlers

package
v0.0.0-...-fc0cb9f Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidProductPath = fmt.Errorf("Invalid Path, path should be /products/[id]")

ErrInvalidProductPath is an error message when the product path is not valid

Functions

This section is empty.

Types

type GenericError

type GenericError struct {
	Message string `json:"message"`
}

GenericError is a generic error message returned by a server

type Goodbye

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

func NewGoodbye

func NewGoodbye(l *log.Logger) *Goodbye

func (*Goodbye) ServeHTTP

func (g *Goodbye) ServeHTTP(rw http.ResponseWriter, request *http.Request)

type Hello

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

func NewHello

func NewHello(l *log.Logger) *Hello

func (*Hello) ServeHTTP

func (h *Hello) ServeHTTP(rw http.ResponseWriter, request *http.Request)

type KeyProduct

type KeyProduct struct{}

KeyProduct is a key used for the Product object in the context

type Products

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

Products handler for getting and updating products

func NewProducts

func NewProducts(l *log.Logger, v *data.Validation) *Products

NewProducts returns a new products handler with the given logger

func (*Products) Delete

func (p *Products) Delete(rw http.ResponseWriter, r *http.Request)

Delete handles DELETE requests and removes items from the database

func (*Products) ListAll

func (p *Products) ListAll(rw http.ResponseWriter, r *http.Request)

ListAll handles GET requests and returns all current products

func (*Products) ListSingle

func (p *Products) ListSingle(rw http.ResponseWriter, r *http.Request)

ListSingle handles GET requests

func (*Products) MiddlewareValidateProduct

func (p *Products) MiddlewareValidateProduct(next http.Handler) http.Handler

MiddlewareValidateProduct validates the product in the request and calls next if ok

func (*Products) Update

func (p *Products) Update(rw http.ResponseWriter, r *http.Request)

Update handles PUT requests to update products

type ValidationError

type ValidationError struct {
	Messages []string `json:"messages"`
}

ValidationError is a collection of validation error messages

Jump to

Keyboard shortcuts

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