catalogue

package module
v0.0.0-...-194e51b Latest Latest
Warning

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

Go to latest
Published: May 3, 2023 License: Apache-2.0 Imports: 17 Imported by: 0

README

Build Status Coverage Status Go Report Card Microbadger

Catalogue

A sqwatch-demo service that provides catalogue/product information. This service is built, tested and released by travis.

Bugs, Feature Requests and Contributing

We'd love to see community contributions. We like to keep it simple and use Github issues to track bugs and feature requests and pull requests to manage contributions.

API Spec

Checkout the API Spec here

To build this service
Dependencies
go get -u github.com/FiloSottile/gvt
gvt restore
Go tools

In order to build the project locally you need to make sure that the repository directory is located in the correct $GOPATH directory: $GOPATH/src/github.com/sqwatch-demo/catalogue/. Once that is in place you can build by running:

cd $GOPATH/src/github.com/sqwatch-demo/catalogue/cmd/cataloguesvc/
go build -o catalogue

The result is a binary named catalogue, in the current directory.

Docker

docker-compose build

To run the service on port 8080
Go native

If you followed to Go build instructions, you should have a "catalogue" binary in $GOPATH/src/github.com/sqwatch-demo/catalogue/cmd/cataloguesvc/. To run it use:

./catalogue
Docker

docker-compose up

Run tests before submitting PRs

make test

Check whether the service is alive

curl http://localhost:8080/health

Use the service endpoints

curl http://localhost:8080/catalogue

Push the service to Docker Container Registry

GROUP=weaveworksdemos COMMIT=test ./scripts/push.sh

Test Zipkin

To test with Zipkin

docker-compose -f docker-compose-zipkin.yml build
docker-compose -f docker-compose-zipkin.yml up

It takes about 10 seconds to seed data

you should see it at: http://localhost:9411/

be sure to hit the "Find Traces" button. You may need to reload the page.

when done you can run:

docker-compose -f docker-compose-zipkin.yml down

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrDBConnection = errors.New("database connection error")

ErrDBConnection is returned when connection with the database fails.

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, tracer stdopentracing.Tracer) *mux.Router

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, tracer stdopentracing.Tracer) Endpoints

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

type Health

type Health struct {
	Service string `json:"service"`
	Status  string `json:"status"`
	Time    string `json:"time"`
}

Health describes the health of a 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, error) // GET /catalogue
	Count(tags []string) (int, error)                                        // GET /catalogue/size
	Get(id string) (Sock, error)                                             // GET /catalogue/{id}
	Tags() ([]string, error)                                                 // GET /tags
	Health() []Health                                                        // GET /health
}

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

func NewCatalogueService

func NewCatalogueService(db *sqlx.DB, logger log.Logger) Service

NewCatalogueService returns an implementation of the Service interface, with connection to an SQL database.

type Sock

type Sock struct {
	ID          string   `json:"id" db:"id"`
	Name        string   `json:"name" db:"name"`
	Description string   `json:"description" db:"description"`
	ImageURL    []string `json:"imageUrl" db:"-"`
	ImageURL_1  string   `json:"-" db:"image_url_1"`
	ImageURL_2  string   `json:"-" db:"image_url_2"`
	Price       float32  `json:"price" db:"price"`
	Count       int      `json:"count" db:"count"`
	Tags        []string `json:"tag" db:"-"`
	TagString   string   `json:"-" db:"tag_name"`
}

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