carriers

package
v0.0.0-...-e18c8c3 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2023 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoOffersFound         = errors.New("no offers found")
	ErrFailedToApplyOption   = errors.New("failed to apply option")
	ErrFailedToCreateMetrics = errors.New("failed to create metric from provider")
)
View Source
var Defaults = []Option{
	WithMeter(otel.Meter("github.com/andrewhowdencom/courses.pito/delivery-service/carriers")),
}

Functions

This section is empty.

Types

type Carrier

type Carrier interface {
	// Query allows a provider to return a list of possible delivery options, or an error if there is a failure
	// in some way to query the service.
	Query(*Package) ([]*DeliveryOption, error)
}

Carrier is the interface that all carriers must meet. It ensure that we can provide a standard set of information, and get an appropriate response.

type Carriers

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

Carriers is a wrapper around all individual carriers to aggregate the results from those carriers into a single set of delivery options.

Later it will be extended to include statistics for each carrier.

func New

func New(opts ...Option) (*Carriers, error)

New generates a new set of carriers. There are a series of default options that should be extended when this function is used. For example,

New(append(Defaults, WithCarrier(...))

func (*Carriers) Query

func (c *Carriers) Query(in *Package) ([]*DeliveryOption, error)

Query takes a single package and returns the aggregated results from all delivery providers.

type DeliveryOption

type DeliveryOption struct {
	// The provider that expects to fulfil this method
	Provider string `json:"provider"`

	// The cost of the delivery option, should it be booked
	Cost *money.Money `json:"cost"`

	// The estimated arrival (within 6 hours) that the package will be delivered.
	Arrival time.Time `json:"arrival"`
}

DeliveryOption is an option that can be booked for a delivery.

type Option

type Option func(car *Carriers) error

func WithCarrier

func WithCarrier(nc Carrier) Option

WithCarrier adds a carrier to the carriers primitive

func WithMeter

func WithMeter(mp metric.Meter) Option

WithMeter applies a specific meter provider to the carriers. Used mostly in testing.

type Package

type Package struct {
	// The distance between two points, measured in milimeters
	Width, Height, Depth int64

	// The weight of an object, measured in grams.
	Weight int64
}

Package is a request for a delivery options.

Jump to

Keyboard shortcuts

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