api

package
v0.0.0-...-7affdec Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2019 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidJson = errors.New("Invalid json")
View Source
var ErrInvalidPaymentAmount = errors.New("Invalid payment amount")
View Source
var (
	HTTPLatency = prometheus.NewHistogramVec(prometheus.HistogramOpts{
		Name:    "http_request_duration_seconds",
		Help:    "Time (in seconds) spent serving HTTP requests.",
		Buckets: prometheus.DefBuckets,
	}, []string{"method", "path", "status_code", "isWS"})
)

Functions

func MakeAuthoriseEndpoint

func MakeAuthoriseEndpoint(s Service) endpoint.Endpoint

MakeListEndpoint returns an endpoint via the given service.

func MakeHTTPHandler

func MakeHTTPHandler(ctx context.Context, e Endpoints, 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 WireUp

func WireUp(ctx context.Context, declineAmount float32, tracer stdopentracing.Tracer, serviceName string) (http.Handler, log.Logger)

Types

type Authorisation

type Authorisation struct {
	Authorised bool   `json:"authorised"`
	Message    string `json:"message"`
}

type AuthoriseRequest

type AuthoriseRequest struct {
	Amount float32 `json:"amount"`
}

AuthoriseRequest represents a request for payment authorisation. The Amount is the total amount of the transaction

type AuthoriseResponse

type AuthoriseResponse struct {
	Authorisation Authorisation
	Err           error
}

AuthoriseResponse returns a response of type Authorisation and an error, Err.

type Endpoints

type Endpoints struct {
	AuthoriseEndpoint 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"`
}

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 {
	Authorise(total float32) (Authorisation, error) // GET /paymentAuth
	Health() []Health                               // GET /health
}

func NewAuthorisationService

func NewAuthorisationService(declineOverAmount float32) 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 UnmarshalKeyError

type UnmarshalKeyError struct {
	Key  string
	JSON string
}

func (*UnmarshalKeyError) Error

func (e *UnmarshalKeyError) Error() string

Jump to

Keyboard shortcuts

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