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

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIHandler

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

APIHandler implements REST API handlers of Puppy.

func NewAPIHandler

func NewAPIHandler(storer Storer) *APIHandler

NewAPIHandler creates a APIHandler with given storer.

func (*APIHandler) HandleDeletePuppy

func (a *APIHandler) HandleDeletePuppy(w http.ResponseWriter, r *http.Request)

HandleDeletePuppy deletes puppy in store by id.

func (*APIHandler) HandleGetPuppyByID

func (a *APIHandler) HandleGetPuppyByID(w http.ResponseWriter, r *http.Request)

HandleGetPuppyByID retrieves puppy by id.

func (*APIHandler) HandlePostPuppy

func (a *APIHandler) HandlePostPuppy(w http.ResponseWriter, r *http.Request)

HandlePostPuppy adds puppy into the store.

func (*APIHandler) HandlePutPuppy

func (a *APIHandler) HandlePutPuppy(w http.ResponseWriter, r *http.Request)

HandlePutPuppy updates puppy in the store.

func (*APIHandler) WireRoutes

func (a *APIHandler) WireRoutes(r chi.Router)

WireRoutes route requests to corresponding REST API handler method.

type ErrCode

type ErrCode uint32
const (
	ErrInvalid   ErrCode = 400
	ErrNotFound  ErrCode = 404
	ErrBadFormat ErrCode = 406
	ErrInternal  ErrCode = 500
)

func (ErrCode) String

func (e ErrCode) String() string

type Error

type Error struct {
	Message string
	Code    ErrCode
	Cause   error
}

func ErrorEf

func ErrorEf(code ErrCode, cause error, format string, args ...interface{}) *Error

func (*Error) Error

func (e *Error) Error() string

type Puppy

type Puppy struct {
	ID     uint64  `json:"id,omitempty"`
	Breed  string  `json:"breed"`
	Colour string  `json:"colour"`
	Value  float64 `json:"value"`
}

func (*Puppy) Validate

func (p *Puppy) Validate() error

type Storer

type Storer interface {
	CreatePuppy(puppy Puppy) (uint64, error)
	ReadPuppy(id uint64) (Puppy, error)
	UpdatePuppy(puppy Puppy) error
	DeletePuppy(id uint64) error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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