service

package
v0.0.0-...-8b501b0 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Aggregator

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

Aggregator collects and returns price quotes from a set of downstream providers.

func NewAggregator

func NewAggregator(vendorID string, providerAddrs []string) *Aggregator

NewAggregator returns a new Aggregator instance that queries the providers at providerAddrs and returns back the results.

func (*Aggregator) GetQuote

GetQuote implements proto.QuoteServiceServer.

func (*Aggregator) Serve

func (a *Aggregator) Serve(ctx context.Context) (string, error)

Serve listens for incoming connections on a random open port until ctx expires. It returns back the address that the server is listening on.

type Gateway

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

Gateway simulates an API gateway that would handle requests from a front-end.

func NewGateway

func NewGateway(serviceName, aggrAddr string) (*Gateway, error)

NewGateway returns a Gateway that retrieves quotes from a downstream aggregator listening at aggrAddr.

func (*Gateway) Close

func (gw *Gateway) Close() error

Close shuts down the gateway and terminates any outgoing connections.

func (*Gateway) CollectQuotes

func (gw *Gateway) CollectQuotes(ctx context.Context, SKU string) (map[string]float64, error)

CollectQuotes obtains a list of price quotes for SKU and returns them as a map where the key is the vendor name and the value is the price.

type Provider

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

Provider simulates a vendor service that returns price quotes for an SKU.

func NewProvider

func NewProvider(vendorID string) *Provider

NewProvider returns a new Provider instance with the specified vendor ID.

func (*Provider) GetQuote

func (p *Provider) GetQuote(ctx context.Context, req *proto.QuotesRequest) (*proto.QuotesResponse, error)

GetQuote implements proto.QuoteServiceServer.

func (*Provider) Serve

func (p *Provider) Serve(ctx context.Context) (string, error)

Serve listens for incoming connections on a random open port until ctx expires. It returns back the address that the server is listening on.

Jump to

Keyboard shortcuts

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