catalogue

package
v0.0.0-...-430864d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 8, 2016 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("not found")

ErrNotFound is returned when there is no sock for a given ID.

Functions

func MakeCountEndpoint

func MakeCountEndpoint(s Service) endpoint.Endpoint

MakeCountEndpoint returns an endpoint via the given service.

func MakeGetEndpoint

func MakeGetEndpoint(s Service) endpoint.Endpoint

MakeGetEndpoint returns an endpoint via the given service.

func MakeHTTPHandler

func MakeHTTPHandler(ctx context.Context, e Endpoints, imagePath string, logger log.Logger) http.Handler

MakeHTTPHandler mounts the endpoints into a REST-y HTTP handler.

func MakeHealthEndpoint

func MakeHealthEndpoint(s Service) endpoint.Endpoint

MakeHealthEndpoint returns current health of the given service.

func MakeListEndpoint

func MakeListEndpoint(s Service) endpoint.Endpoint

MakeListEndpoint returns an endpoint via the given service.

func MakeTagsEndpoint

func MakeTagsEndpoint(s Service) endpoint.Endpoint

MakeTagsEndpoint returns an endpoint via the given service.

Types

type Endpoints

type Endpoints struct {
	ListEndpoint   endpoint.Endpoint
	CountEndpoint  endpoint.Endpoint
	GetEndpoint    endpoint.Endpoint
	TagsEndpoint   endpoint.Endpoint
	HealthEndpoint endpoint.Endpoint
}

Endpoints collects the endpoints that comprise the Service.

func MakeEndpoints

func MakeEndpoints(s Service) Endpoints

MakeEndpoints returns an Endpoints structure, where each endpoint is backed by the given service.

type Middleware

type Middleware func(Service) Service

Middleware decorates a service.

func LoggingMiddleware

func LoggingMiddleware(logger log.Logger) Middleware

LoggingMiddleware logs method calls, parameters, results, and elapsed time.

type Service

type Service interface {
	List(tags []string, order string, pageNum, pageSize int) []Sock // GET /catalogue
	Count(tags []string) int                                        // GET /catalogue/size
	Get(id string) (Sock, error)                                    // GET /catalogue/{id}
	Tags() []string                                                 // GET /tags
}

Service is the catalogue service, providing read operations on a saleable catalogue of sock products.

func NewFixedService

func NewFixedService(socks []Sock, tags []string) Service

NewFixedService returns a simple implementation of the Service interface, fixed over a predefined set of socks and tags. In a real service you'd probably construct this with a database handle to your socks DB, etc.

type Sock

type Sock struct {
	ID          string   `json:"id"`
	Name        string   `json:"name"`
	Description string   `json:"description"`
	ImageURL    []string `json:"imageUrl"`
	Price       float32  `json:"price"`
	Count       int      `json:"count"`
	Tags        []string `json:"tag"`
}

Sock describes the thing on offer in the catalogue.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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