package addservice

import "github.com/go-kit/kit/examples/addsvc/pkg/addservice"

Index

Variables

var (
	// ErrTwoZeroes is an arbitrary business rule for the Add method.
	ErrTwoZeroes = errors.New("can't sum two zeroes")

	// ErrIntOverflow protects the Add method. We've decided that this error
	// indicates a misbehaving service and should count against e.g. circuit
	// breakers. So, we return it directly in endpoints, to illustrate the
	// difference. In a real service, this probably wouldn't be the case.
	ErrIntOverflow = errors.New("integer overflow")

	// ErrMaxSizeExceeded protects the Concat method.
	ErrMaxSizeExceeded = errors.New("result exceeds maximum size")
)

Types

type Middleware

type Middleware func(Service) Service

Middleware describes a service (as opposed to endpoint) middleware.

func InstrumentingMiddleware

func InstrumentingMiddleware(ints, chars metrics.Counter) Middleware

InstrumentingMiddleware returns a service middleware that instruments the number of integers summed and characters concatenated over the lifetime of the service.

func LoggingMiddleware

func LoggingMiddleware(logger log.Logger) Middleware

LoggingMiddleware takes a logger as a dependency and returns a ServiceMiddleware.

type Service

type Service interface {
	Sum(ctx context.Context, a, b int) (int, error)
	Concat(ctx context.Context, a, b string) (string, error)
}

Service describes a service that adds things together.

func New

func New(logger log.Logger, ints, chars metrics.Counter) Service

New returns a basic Service with all of the expected middlewares wired in.

func NewBasicService

func NewBasicService() Service

NewBasicService returns a naïve, stateless implementation of Service.

Source Files

middleware.go service.go

Version
v0.9.0
Published
Jun 24, 2019
Platform
linux/amd64
Imports
4 packages
Last checked
10 minutes ago

Tools for package owners.