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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReportLostPuppy

func ReportLostPuppy(puppyID uint64, lostSvcURL string)

ReportLostPuppy sends an async http request to lost puppy service

Types

type APIHandler

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

APIHandler implements REST API handlers of Puppy.

func NewAPIHandler

func NewAPIHandler(storer Storer, lostSvcURL string) *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 LostAPIHandler

type LostAPIHandler struct{}

LostAPIHandler implements REST API handler of lost service.

func NewLostAPIHandler

func NewLostAPIHandler() *LostAPIHandler

NewLostAPIHandler creates a LostAPIHandler.

func (*LostAPIHandler) HandlePostLostPuppy

func (a *LostAPIHandler) HandlePostLostPuppy(w http.ResponseWriter, r *http.Request)

HandlePostLostPuppy handles http request to lost puppy service.

func (*LostAPIHandler) WireRoutes

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

WireRoutes route requests to corresponding REST API handler method.

type LostPuppyRequest

type LostPuppyRequest struct {
	ID uint64 `json:"id"`
}

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