data

package
v0.0.0-...-37ea4fd Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2023 License: MIT Imports: 5 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)

Add new product to the database

func DeleteProduct

func DeleteProduct(id int) error

func FromJSON

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

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

func ToJSON

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

ToJSON serializes the given interface into a string based JSON format

func UpdateProduct

func UpdateProduct(p Product) error

Types

type Product

type Product struct {
	// the id for the product
	//
	// required: false
	// min: 1
	ID int `json:"id"` // Unique identifier for the product

	// 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:"required,gt=0"`

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

Product defines the structure for an API product swagger: model

func GetProductByID

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

GetProductByID is a func that returns the single product by id from the database If a product is not found this function returns a ProductNotFound error

type Products

type Products []*Product

Products is a collection of Product or slice of product

func GetProducts

func GetProducts() Products

GetProducts returns a list of products

type Validation

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

func NewValidation

func NewValidation() *Validation

creating a new validation of validation type

func (*Validation) Validate

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

validate finc

type ValidationError

type ValidationError struct {
	validator.FieldError
}

this wraps all the validators field errors

func (ValidationError) Error

func (v ValidationError) Error() string

type ValidationErrors

type ValidationErrors []ValidationError

collection of ValidationError

func (ValidationErrors) Errors

func (v 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