kit: github.com/go-kit/kit/examples/shipping/cargo Index | Files

package cargo

import "github.com/go-kit/kit/examples/shipping/cargo"

Package cargo contains the heart of the domain model.

Index

Package Files

cargo.go delivery.go handling.go itinerary.go

Variables

var ErrUnknown = errors.New("unknown cargo")

ErrUnknown is used when a cargo could not be found.

type Cargo Uses

type Cargo struct {
    TrackingID         TrackingID
    Origin             location.UNLocode
    RouteSpecification RouteSpecification
    Itinerary          Itinerary
    Delivery           Delivery
}

Cargo is the central class in the domain model.

func New Uses

func New(id TrackingID, rs RouteSpecification) *Cargo

New creates a new, unrouted cargo.

func (*Cargo) AssignToRoute Uses

func (c *Cargo) AssignToRoute(itinerary Itinerary)

AssignToRoute attaches a new itinerary to this cargo.

func (*Cargo) DeriveDeliveryProgress Uses

func (c *Cargo) DeriveDeliveryProgress(history HandlingHistory)

DeriveDeliveryProgress updates all aspects of the cargo aggregate status based on the current route specification, itinerary and handling of the cargo.

func (*Cargo) SpecifyNewRoute Uses

func (c *Cargo) SpecifyNewRoute(rs RouteSpecification)

SpecifyNewRoute specifies a new route for this cargo.

type Delivery Uses

type Delivery struct {
    Itinerary               Itinerary
    RouteSpecification      RouteSpecification
    RoutingStatus           RoutingStatus
    TransportStatus         TransportStatus
    NextExpectedActivity    HandlingActivity
    LastEvent               HandlingEvent
    LastKnownLocation       location.UNLocode
    CurrentVoyage           voyage.Number
    ETA                     time.Time
    IsMisdirected           bool
    IsUnloadedAtDestination bool
}

Delivery is the actual transportation of the cargo, as opposed to the customer requirement (RouteSpecification) and the plan (Itinerary).

func DeriveDeliveryFrom Uses

func DeriveDeliveryFrom(rs RouteSpecification, itinerary Itinerary, history HandlingHistory) Delivery

DeriveDeliveryFrom creates a new delivery snapshot based on the complete handling history of a cargo, as well as its route specification and itinerary.

func (Delivery) IsOnTrack Uses

func (d Delivery) IsOnTrack() bool

IsOnTrack checks if the delivery is on track.

func (Delivery) UpdateOnRouting Uses

func (d Delivery) UpdateOnRouting(rs RouteSpecification, itinerary Itinerary) Delivery

UpdateOnRouting creates a new delivery snapshot to reflect changes in routing, i.e. when the route specification or the itinerary has changed but no additional handling of the cargo has been performed.

type HandlingActivity Uses

type HandlingActivity struct {
    Type         HandlingEventType
    Location     location.UNLocode
    VoyageNumber voyage.Number
}

HandlingActivity represents how and where a cargo can be handled, and can be used to express predictions about what is expected to happen to a cargo in the future.

type HandlingEvent Uses

type HandlingEvent struct {
    TrackingID TrackingID
    Activity   HandlingActivity
}

HandlingEvent is used to register the event when, for instance, a cargo is unloaded from a carrier at a some location at a given time.

type HandlingEventFactory Uses

type HandlingEventFactory struct {
    CargoRepository    Repository
    VoyageRepository   voyage.Repository
    LocationRepository location.Repository
}

HandlingEventFactory creates handling events.

func (*HandlingEventFactory) CreateHandlingEvent Uses

func (f *HandlingEventFactory) CreateHandlingEvent(registered time.Time, completed time.Time, id TrackingID,
    voyageNumber voyage.Number, unLocode location.UNLocode, eventType HandlingEventType) (HandlingEvent, error)

CreateHandlingEvent creates a validated handling event.

type HandlingEventRepository Uses

type HandlingEventRepository interface {
    Store(e HandlingEvent)
    QueryHandlingHistory(TrackingID) HandlingHistory
}

HandlingEventRepository provides access a handling event store.

type HandlingEventType Uses

type HandlingEventType int

HandlingEventType describes type of a handling event.

const (
    NotHandled HandlingEventType = iota
    Load
    Unload
    Receive
    Claim
    Customs
)

Valid handling event types.

func (HandlingEventType) String Uses

func (t HandlingEventType) String() string

type HandlingHistory Uses

type HandlingHistory struct {
    HandlingEvents []HandlingEvent
}

HandlingHistory is the handling history of a cargo.

func (HandlingHistory) MostRecentlyCompletedEvent Uses

func (h HandlingHistory) MostRecentlyCompletedEvent() (HandlingEvent, error)

MostRecentlyCompletedEvent returns most recently completed handling event.

type Itinerary Uses

type Itinerary struct {
    Legs []Leg `json:"legs"`
}

Itinerary specifies steps required to transport a cargo from its origin to destination.

func (Itinerary) FinalArrivalLocation Uses

func (i Itinerary) FinalArrivalLocation() location.UNLocode

FinalArrivalLocation returns the end of the itinerary.

func (Itinerary) FinalArrivalTime Uses

func (i Itinerary) FinalArrivalTime() time.Time

FinalArrivalTime returns the expected arrival time at final destination.

func (Itinerary) InitialDepartureLocation Uses

func (i Itinerary) InitialDepartureLocation() location.UNLocode

InitialDepartureLocation returns the start of the itinerary.

func (Itinerary) IsEmpty Uses

func (i Itinerary) IsEmpty() bool

IsEmpty checks if the itinerary contains at least one leg.

func (Itinerary) IsExpected Uses

func (i Itinerary) IsExpected(event HandlingEvent) bool

IsExpected checks if the given handling event is expected when executing this itinerary.

type Leg Uses

type Leg struct {
    VoyageNumber   voyage.Number     `json:"voyage_number"`
    LoadLocation   location.UNLocode `json:"from"`
    UnloadLocation location.UNLocode `json:"to"`
    LoadTime       time.Time         `json:"load_time"`
    UnloadTime     time.Time         `json:"unload_time"`
}

Leg describes the transportation between two locations on a voyage.

func NewLeg Uses

func NewLeg(voyageNumber voyage.Number, loadLocation, unloadLocation location.UNLocode, loadTime, unloadTime time.Time) Leg

NewLeg creates a new itinerary leg.

type Repository Uses

type Repository interface {
    Store(cargo *Cargo) error
    Find(id TrackingID) (*Cargo, error)
    FindAll() []*Cargo
}

Repository provides access a cargo store.

type RouteSpecification Uses

type RouteSpecification struct {
    Origin          location.UNLocode
    Destination     location.UNLocode
    ArrivalDeadline time.Time
}

RouteSpecification Contains information about a route: its origin, destination and arrival deadline.

func (RouteSpecification) IsSatisfiedBy Uses

func (s RouteSpecification) IsSatisfiedBy(itinerary Itinerary) bool

IsSatisfiedBy checks whether provided itinerary satisfies this specification.

type RoutingStatus Uses

type RoutingStatus int

RoutingStatus describes status of cargo routing.

const (
    NotRouted RoutingStatus = iota
    Misrouted
    Routed
)

Valid routing statuses.

func (RoutingStatus) String Uses

func (s RoutingStatus) String() string

type TrackingID Uses

type TrackingID string

TrackingID uniquely identifies a particular cargo.

func NextTrackingID Uses

func NextTrackingID() TrackingID

NextTrackingID generates a new tracking ID. TODO: Move to infrastructure(?)

type TransportStatus Uses

type TransportStatus int

TransportStatus describes status of cargo transportation.

const (
    NotReceived TransportStatus = iota
    InPort
    OnboardCarrier
    Claimed
    Unknown
)

Valid transport statuses.

func (TransportStatus) String Uses

func (s TransportStatus) String() string

Package cargo imports 6 packages (graph) and is imported by 54 packages. Updated 2016-11-09. Refresh now. Tools for package owners.