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

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MapStore

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

type MapStore map[int]Puppy This will serve as our in-memory DB

func NewMapStore

func NewMapStore() *MapStore

func (*MapStore) CreatePuppy

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

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
}

type Storer

type Storer interface {
	CreatePuppy(puppy *Puppy) int // takes an address as an argument 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
	// contains filtered or unexported fields
}

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

func NewSyncStore

func NewSyncStore() *SyncStore

func (*SyncStore) CreatePuppy

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

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