data

package
v6.0.0-...-ff4b850 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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

Functions

func AddProduct

func AddProduct(p *Product)

func UpdateProduct

func UpdateProduct(id int, p *Product) error

Types

type Product

type Product struct {
	ID          int     `json:"id"`
	Name        string  `json:"name" validate:"required"`
	Description string  `json:"description"`
	Price       float32 `json:"price" validate:"gt=0"`
	SKU         string  `json:"sku" validate:"required,sku"`
	CreatedOn   string  `json:"-"`
	UpdatedOn   string  `json:"-"`
	DeletedOn   string  `json:"-"`
}

Product defines the structure for an API product

func (*Product) FromJSON

func (p *Product) FromJSON(r io.Reader) error

func (*Product) ToJSON

func (p *Product) ToJSON(w io.Writer) error

func (*Product) Validate

func (p *Product) Validate() error

type Products

type Products []*Product

Products is a collection of Product

func GetProducts

func GetProducts() Products

GetProducts returns a list of products

func (*Products) ToJSON

func (p *Products) ToJSON(w io.Writer) error

ToJSON serializes the contents of the collection to JSON NewEncoder provides better performance than json.Unmarshal as it does not have to buffer the output into an in-memory slice of bytes this reduces allocations and the overheads of the service

https://golang.org/pkg/encoding/json/#NewEncoder

Jump to

Keyboard shortcuts

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