puppy

package
v0.0.0-...-cf576ff Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2020 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ErrUnknown is used when an unknown error occurred
	ErrUnknown uint16 = iota
	// ErrInvalidValue is used when the value for the puppy is negative
	ErrInvalidValue
	// ErrIDNotFound is used when attempting to read a non-existing entry
	ErrIDNotFound
)

Error codes

Variables

This section is empty.

Functions

func ValidateValue

func ValidateValue(value float32) error

ValidateValue validates that value for the puppy is a positive value

Types

type Error

type Error struct {
	Code    uint16 `json:"code"`
	Message string `json:"message"`
}

Error struct to identify errors in Puppy store

func Errorf

func Errorf(code uint16, format string, args ...interface{}) *Error

Errorf creates a new Error with formatting

func (*Error) Error

func (e *Error) Error() string

type Puppy

type Puppy struct {
	Breed  string  `json:"breed"`
	Colour string  `json:"color,omitempty"`
	ID     int16   `json:"id"`
	Value  float32 `json:"value"`
}

Puppy represents an item in the puppy store

func (*Puppy) String

func (p *Puppy) String() string

type RestServer

type RestServer struct {
	DB Storer
}

RestServer store for puppies

func (*RestServer) SetupRoutes

func (rs *RestServer) SetupRoutes(db Storer) *chi.Mux

SetupRoutes setups the routes for the server

type Storer

type Storer interface {
	CreatePuppy(Puppy) error
	ReadPuppy(ID int16) (Puppy, error)
	UpdatePuppy(ID int16, p *Puppy) error
	DeletePuppy(ID int16) error
}

Storer CRUD methods for the Puppy store

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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