data

package
v0.0.0-...-722a0d2 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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

ErrProductNotFound is an error message when client requesting a product that can not be found or doesn't exist

Functions

func FromJSON

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

FromJSON used for converting JSON formatted data to struct of Product

func ToJSON

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

ToJSON used for converting the struct of Product to JSON. It has better performance than json.marshal since it doesn't have to buffer the output into memory

Types

type Product

type Product struct {
	// the id for the product
	//
	// required: false
	// min: 1
	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 float64 `json:"price" validate:"gt=0,required"`

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

Product defines the structure for an API product swagger:model

type Products

type Products []*Product

Products is a reference to struct of Product

type ProductsDB

type ProductsDB struct {
	// contains filtered or unexported fields
}

ProductsDB is used to query data with

func NewProductsDB

func NewProductsDB(log hclog.Logger, cc currency.CurrencyClient) *ProductsDB

NewProductsDB do something

func (*ProductsDB) AddProduct

func (pdb *ProductsDB) AddProduct(product Product)

AddProduct is a function to add the requested product

func (*ProductsDB) DeleteProduct

func (pdb *ProductsDB) DeleteProduct(id int) error

DeleteProduct is a function to delete the requested product

func (*ProductsDB) GetProductByID

func (pdb *ProductsDB) GetProductByID(id int, currency string) (*Product, error)

GetProductByID return a product

func (*ProductsDB) GetProductList

func (pdb *ProductsDB) GetProductList(currency string) (Products, error)

GetProductList do something

func (*ProductsDB) UpdateProduct

func (pdb *ProductsDB) UpdateProduct(p Product) error

UpdateProduct is a function to update the requested product

type Validation

type Validation struct {
	// contains filtered or unexported fields
}

Validation is a struct for validation

func NewValidator

func NewValidator() *Validation

NewValidator creates a new Validation type

func (*Validation) Validate

func (v *Validation) Validate(i interface{}) ValidationErrors

Validate used for struct validation

type ValidationError

type ValidationError struct {
	validator.FieldError
}

ValidationError wraps the validators FieldError so we do not expose this to out code

func (ValidationError) Error

func (ve ValidationError) Error() string

type ValidationErrors

type ValidationErrors []ValidationError

ValidationErrors is an error collection of ValidationError

func (ValidationErrors) Errors

func (ves ValidationErrors) Errors() []string

Errors converts the slice into a string slice

Jump to

Keyboard shortcuts

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