handlers

package
v0.0.0-...-e26ef75 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package classification of Product API

Documentation for Product API

Schemes: http
BasePath: /
Version: 1.0.0

Consumes:
- application/json

Produces:
- application/json

swagger:meta

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 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) Create

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

Create handles POST requests to add new products

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) MiddlewareContentType

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

MiddlewareContentType is a convenience handler for adding the application/json content type to every response

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