data

package
v0.0.0-...-0d7a5af Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2023 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)

AddProduct adds a new product

func UpdateProduct

func UpdateProduct(id int, p *Product) error

Types

type Product

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

swagger:model Product

func (*Product) FromJSON

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

func (*Product) Validate

func (p *Product) Validate() error

Products Struct validation

type Products

type Products []*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