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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetupRoutes

func SetupRoutes(r chi.Router, rh RestHandler)

SetupRoutes provides the routes for this REST API.

Types

type ErrCode

type ErrCode uint32
const (
	// ErrInvalidInput is used for any user input error
	ErrInvalidInput ErrCode = iota
	// ErrNotFound is used for puppy ID does not exist
	ErrNotFound
)

func (ErrCode) String

func (e ErrCode) String() string

type Error

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

func Errorf

func Errorf(code ErrCode, message string, args ...interface{}) *Error

Errorf creates a new Error with formatting

func (*Error) Error

func (e *Error) Error() string

type MapStore

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

func NewMapStore

func NewMapStore() *MapStore

NewMapStore initialise a new MapStore

func (*MapStore) CreatePuppy

func (m *MapStore) CreatePuppy(p *Puppy) (uint32, error)

CreatePuppy create a new puppy and store in mapStore.

func (MapStore) DeletePuppy

func (m MapStore) DeletePuppy(id uint32) error

DeletePuppy delete the puppy given the id.

func (MapStore) ReadPuppy

func (m MapStore) ReadPuppy(id uint32) (*Puppy, error)

ReadPuppy read a puppy given its id. It returns the pointer to that puppy.

func (MapStore) UpdatePuppy

func (m MapStore) UpdatePuppy(id uint32, p *Puppy) error

UpdatePuppy updates the store with key of id with the new puppy.

type Puppy

type Puppy struct {
	ID    uint32 `json:"id"`
	Breed string `json:"breed"`
	Color string `json:"color"`
	Value string `json:"value,omitempty"`
}

type RestHandler

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

RestHandler provides a puppy storer to store the puppies

func NewRestHandler

func NewRestHandler(storer Storer) *RestHandler

NewRestHandler is a factory method that makes new storer

func (*RestHandler) HandleDelete

func (rh *RestHandler) HandleDelete(w http.ResponseWriter, r *http.Request)

HandleDelete deletes the puppy with by id and display the results.

func (*RestHandler) HandleGet

func (rh *RestHandler) HandleGet(w http.ResponseWriter, r *http.Request)

HandleGet gets the puppy by id and displays the results.

func (*RestHandler) HandlePost

func (rh *RestHandler) HandlePost(w http.ResponseWriter, r *http.Request)

HandlePost post a new puppy and then display the results.

func (*RestHandler) HandlePut

func (rh *RestHandler) HandlePut(w http.ResponseWriter, r *http.Request)

HandlePut updates the existing puppy with new fields in the payload.

type Storer

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

type SyncStore

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

func NewSyncStore

func NewSyncStore() *SyncStore

NewMapStore initialise a new SyncStore

func (*SyncStore) CreatePuppy

func (s *SyncStore) CreatePuppy(p *Puppy) (uint32, error)

CreatePuppy create a new puppy and store in mapStore.

func (*SyncStore) DeletePuppy

func (s *SyncStore) DeletePuppy(id uint32) error

DeletePuppy delete the puppy given the id.

func (*SyncStore) ReadPuppy

func (s *SyncStore) ReadPuppy(id uint32) (*Puppy, error)

ReadPuppy read a puppy given its id. It returns the pointer to that puppy.

func (*SyncStore) UpdatePuppy

func (s *SyncStore) UpdatePuppy(id uint32, p *Puppy) error

UpdatePuppy updates the store with key of id with the new puppy.

Jump to

Keyboard shortcuts

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