Documentation
¶
Overview ¶
Package demo provides simulated carriers and a flight catalog so the gateway can be exercised end to end without a real interline partner.
Index ¶
Constants ¶
const ( MinConnect = 60 * time.Minute MaxConnect = 8 * time.Hour )
Connection limits for a generated journey. The minimum keeps an itinerary plausible -- an international connection needs time to clear the terminal -- and the maximum keeps it from proposing an overnight sit as a connection.
const ( AVSDaysBack = 2 AVSDaysForward = 2 )
The window of departure dates a simulated carrier publishes around the default booking date.
const AVSInterval = 20 * time.Second
AVSInterval is how often a simulated carrier rebroadcasts availability.
Short, because a demonstration should show the cache filling. A real carrier broadcasts on change rather than on a timer; the periodic form here also exercises the cache's rule that an older assertion never moves state backwards.
Variables ¶
var BookingClasses = []string{"F", "J", "Y", "M", "Z"}
BookingClasses are the classes the demo offers.
Z is always refused by the simulated inventory, which gives the console a reliable way to show an unable response rather than only the happy path.
var Fleet = []Carrier{ {Designator: "BA", Name: "British Airways", TTYAddress: "LHRRMBA", Format: store.FormatTypeB, Hub: "LHR"}, {Designator: "AA", Name: "American Airlines", TTYAddress: "DFWRMAA", Format: store.FormatEDIFACT, Hub: "DFW"}, {Designator: "LH", Name: "Lufthansa", TTYAddress: "FRARMLH", Format: store.FormatTypeB, Hub: "FRA"}, }
Fleet is the default simulated interline environment: three carriers, two wire formats, so a single booking can span both.
var Schedule = []Route{
{"LHR", "JFK", "0800", "1105", "0175", "BA"},
{"LHR", "JFK", "1420", "1725", "0117", "BA"},
{"JFK", "LHR", "1830", "0645", "0112", "BA"},
{"LHR", "FRA", "0705", "0950", "0902", "BA"},
{"DFW", "LHR", "1710", "0705", "0050", "AA"},
{"LHR", "DFW", "1030", "1520", "0051", "AA"},
{"JFK", "DFW", "0900", "1210", "2401", "AA"},
{"FRA", "JFK", "1015", "1300", "0400", "LH"},
{"JFK", "FRA", "1735", "0715", "0401", "LH"},
{"FRA", "LHR", "1145", "1225", "0906", "LH"},
}
Schedule is a small, fixed timetable. It is fixed rather than generated so that a demonstration repeats identically and a screenshot stays accurate.
Functions ¶
func DefaultDate ¶
DefaultDate returns a departure date a month out, which is inside the booking window under any interpretation and avoids demonstrations that break when run near a year boundary.
func ScheduleKeys ¶
ScheduleKeys enumerates every sellable unit a carrier offers on a date: one key per segment per booking class.
Types ¶
type Carrier ¶
type Carrier struct {
// Designator is the two-character airline code.
Designator string
Name string
// TTYAddress is the Type B address this carrier receives on.
TTYAddress string
// Format is the wire encoding this carrier's link speaks. Running a mixed
// fleet is the point: a gateway that only ever sees one encoding has not
// been tested.
Format store.Format
// Hub is the carrier's main base, used to generate a plausible schedule.
Hub string
}
Carrier describes a simulated airline reservation system.
func CarrierByDesignator ¶
CarrierByDesignator looks up a carrier in the fleet.
type Flight ¶
type Flight struct {
Carrier string `json:"carrier"`
FlightNum string `json:"flight_num"`
Board string `json:"board"`
Off string `json:"off"`
Depart string `json:"depart"` // HHMM
Arrive string `json:"arrive"` // HHMM
Classes []string `json:"classes"`
}
Flight is one schedule entry offered to the booking form.
type Journey ¶
type Journey struct {
Origin string `json:"origin"`
Destination string `json:"destination"`
Via string `json:"via,omitempty"`
Legs []Leg `json:"legs"`
Carriers []string `json:"carriers"`
// Interline reports whether more than one carrier is involved.
Interline bool `json:"interline"`
// ConnectMinutes is the ground time at the connecting point.
ConnectMinutes int `json:"connect_minutes"`
}
Journey is an itinerary from an origin to a destination.
An interline journey is one whose legs are operated by different carriers. That is the case worth demonstrating: it produces a single passenger name record that two carriers each hold a piece of, which is the entire reason interline messaging exists.
func InterlineJourneys ¶
func InterlineJourneys() []Journey
InterlineJourneys returns only the multi-carrier itineraries.
func Journeys ¶
func Journeys() []Journey
Journeys enumerates the itineraries the demo schedule can produce: every non-stop, and every single-connection journey whose ground time is plausible.
Interline journeys are listed first, because they are the ones worth looking at: a booking that spans two carriers exercises two links, two dialects and two record locators against one record.
type Leg ¶
type Leg struct {
Carrier string `json:"carrier"`
FlightNum string `json:"flight_num"`
Board string `json:"board"`
Off string `json:"off"`
Depart string `json:"depart"`
Arrive string `json:"arrive"`
// DayOffset is how many days after the journey's first departure this leg
// leaves. A flight that lands the next morning pushes its connection over.
DayOffset int `json:"day_offset"`
}
Leg is one flight in a generated journey.
type Node ¶
type Node struct {
Carrier Carrier
Gateway *gateway.Gateway
Store store.Store
Inventory *gateway.Inventory
// contains filtered or unexported fields
}
Node is a running simulated carrier reservation system.
func StartCarrier ¶
func StartCarrier(ctx context.Context, c Carrier, addr string, bus *gateway.Bus, log *slog.Logger) (*Node, error)
StartCarrier brings up a carrier that connects to the gateway's link server at addr and answers reservation requests from its own inventory.
The link is a real TCP session even when the carrier runs in the same process as the gateway. Simulating the transport away would leave the part most likely to break in production -- framing, reconnection, partial reads -- untested.
type RunningFleet ¶
Fleet holds the running simulated carriers.
func StartFleet ¶
func StartFleet(ctx context.Context, carriers []Carrier, addrFor func(Carrier) string, bus *gateway.Bus, log *slog.Logger) (*RunningFleet, error)
StartFleet brings up every carrier in the fleet. addrFor supplies the gateway listener each carrier dials; a carrier with no address is skipped.
func (*RunningFleet) Node ¶
func (f *RunningFleet) Node(designator string) *Node
Node returns a running carrier by designator.