puppystorer

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: 2 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrNegativePuppyID = 400
	ErrPuppyNotFound   = 404
)

Error codes

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

type Error struct {
	Message string
	Code    int
}

Error (our custom error type) wraps errors with code, message and error itself - what does this even mean??

func (*Error) Error

func (e *Error) Error() string

Error() method lets us satisfy error interface for our custom error type

type MapStore

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

MapStore will serve as our in-memory DB

func NewMapStore

func NewMapStore() *MapStore

NewSyncStore() conveniently creates a new initialised syncstore

func (*MapStore) CreatePuppy

func (ms *MapStore) CreatePuppy(puppy *Puppy) (int, error)

CreatePuppy lets you create a new unique puppy in MapStore

func (*MapStore) DeletePuppy

func (ms *MapStore) DeletePuppy(id int) error

DeletePuppy lets you delete a specific puppy in MapStore

func (*MapStore) ReadPuppy

func (ms *MapStore) ReadPuppy(id int) (*Puppy, error)

ReadPuppy lets you GET a puppy from MapStore if it exists. Else it will return an error

func (*MapStore) UpdatePuppy

func (ms *MapStore) UpdatePuppy(id int, puppy *Puppy) error

UpdatePuppy lets you update a "row" in MapStore

type Puppy

type Puppy struct {
	ID     int
	Breed  string
	Colour string
	Value  float64
}

Puppy data structure stores puppy properties

type Storer

type Storer interface {
	CreatePuppy(puppy *Puppy) (int, error) // takes a pointer which makes sense since you are modifying that object
	ReadPuppy(id int) (*Puppy, error)
	UpdatePuppy(id int, puppy *Puppy) error
	DeletePuppy(id int) error
}

Storer defines standard CRUD operations for Pets

type SyncStore

type SyncStore struct {
	sync.Map

	sync.Mutex
	// contains filtered or unexported fields
}

SyncStore struct. To serve as alternative in-memory DB. It also implements Storer interface

func NewSyncStore

func NewSyncStore() *SyncStore

NewSyncStore() conveniently creates a new initialised syncstore

func (*SyncStore) CreatePuppy

func (m *SyncStore) CreatePuppy(puppy *Puppy) (int, error)

CreatePuppy creates a puppy in sync store. Note we use a pointer receiver for this

func (*SyncStore) DeletePuppy

func (m *SyncStore) DeletePuppy(id int) error

DeletePuppy deletes a puppy in sync store

func (*SyncStore) ReadPuppy

func (m *SyncStore) ReadPuppy(id int) (*Puppy, error)

ReadPuppy retrieves puppy from sync store

func (*SyncStore) UpdatePuppy

func (m *SyncStore) UpdatePuppy(id int, puppy *Puppy) error

UpdatePuppy updates a puppy in sync store

Jump to

Keyboard shortcuts

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