data

package
v0.0.0-...-c6c5b12 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2021 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 DeleteProduct

func DeleteProduct(id int) error

DeleteProduct deletes the product with the given id

func ToJSONInterface

func ToJSONInterface(i interface{}, w io.Writer) error

ToJSON serializes the given interface into a string based JSON format

func UpdateProduct

func UpdateProduct(id int, p *Product) error

UpdateProdict replaces the Product with the given id.

Types

type Product

type Product struct {
	// the id for this product
	//
	// required: true
	ID int `json:"id"`

	// the name for this poduct
	//
	// required: true
	// max length: 255
	Name string `json:"name" validate:"required"`

	// the description for this poduct
	//
	// required: false
	// max length: 10000
	Description string `json:"description"`

	// the price for the product
	//
	// required: true
	// min: 0.01
	Price float32 `json:"price" validate:"gt=0"`

	// the SKU for the product
	//
	// required: true
	// pattern: [a-z]+-[a-z]+-[a-z]+
	SKU       string `json:"sku" validate:"required,sku"`
	CreatedOn string `json:"-"`
	UpdatedOn string `json:"-"`
	DeletedOn string `json:"-"`
}

Product defines the structure for an API product. Product also has relevant struct tags for validation and json encoding. swagger:model

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

func (*Product) FromJSON

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

func (*Product) Validate

func (p *Product) Validate() error

type Products

type Products []*Product

func GetProducts

func GetProducts() Products

func (*Products) ToJSON

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

Jump to

Keyboard shortcuts

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