handlers

package
v0.0.0-...-1ba6939 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package classification of gomicro Product API

Documentation for gomicro 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, cc protos.CurrencyClient) *Products

NewProducts returns a new products handler with the given logger

func (*Products) Create

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

Create handles POST requests to add new products

func (*Products) Delete

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

Delete handles DELETE requests and removes items from the database

func (*Products) ListAll

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

ListAll handles GET requests and returns all current products

func (*Products) ListSingle

func (p *Products) ListSingle(w 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(w 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