data

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: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrProductNotFound = fmt.Errorf("Product not found")

ErrProductNotFound is an error raised when a product can not be found in the database

Functions

func DeleteProduct

func DeleteProduct(id int) error

DeleteProduct deletes a product from the database If a product with the given id does not exist in the database this function returns a ProductNotFound error

func FromJSON

func FromJSON(r io.Reader, obj interface{}) error

FromJSON deserializes the object from JSON string in an io.Reader

func ToJSON

func ToJSON(w io.Writer, obj interface{}) error

ToJSON serializes the Products into a string based JSON format

func UpdateProduct

func UpdateProduct(p Product) error

UpdateProduct replaces a product in the database with the given item. If a product with the given id does not exist in the database this function returns a ProductNotFound error

Types

type Product

type Product struct {
	ID          int     `json:"id"`
	Name        string  `json:"name"`
	Description string  `json:"description"`
	Price       float32 `json:"price"`
	SKU         string  `json:"sku"`
}

Product defines the structure for an API product

func AddProduct

func AddProduct(p Product) Product

AddProduct adds a new product to the database

func GetProductByID

func GetProductByID(id int) (*Product, error)

GetProductByID returns a single product which matches the id from the database. If a product is not found this function returns a ProductNotFound error

type Products

type Products []*Product

Products defines a slice of Product

func GetProducts

func GetProducts() Products

GetProducts returns all products from the database

Jump to

Keyboard shortcuts

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