-
Notifications
You must be signed in to change notification settings - Fork 1
/
json_types.go
95 lines (87 loc) · 3.75 KB
/
json_types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package main
import (
"fmt"
"strings"
"time"
"gopkg.in/gookit/color.v1"
)
// GVATime wraps time for manual parsing
type GVATime struct {
time time.Time
}
func (me *GVATime) String() string {
if me.time.IsZero() {
return ""
}
if ShowAllFlights {
return fmt.Sprint(me.time.Format(LongDisplayTimeFormat))
}
return fmt.Sprint(me.time.Format(ShortDisplayTimeFormat))
}
func (me *GVATime) StringDelay(scheduledTime GVATime) string {
delay := me.time.Sub(scheduledTime.time)
if delay.Minutes() > BigDelayMinutes {
return color.Red.Sprintf(me.String())
} else if delay.Minutes() > FairDelayMinutes {
return color.Yellow.Sprintf(me.String())
} else {
return me.String()
}
}
// UnmarshalJSON implements what is needed to turn JSON-like time in GVATime
func (me *GVATime) UnmarshalJSON(input []byte) error {
strInput := string(input)
strInput = strings.Trim(strInput, `"`)
if strInput == "null" {
return nil
}
newTime, err := time.Parse(JSONTimeFormat, strInput)
if err != nil {
return err
}
me.time = newTime
return nil
}
// Flight contains relevant data extracted during JSON unmarshalling
type Flight struct {
FlightIdentity string `json:"flight_identity"`
DisplayedFlightIdentity string `json:"displayed_flight_identity"`
Airport string `json:"airport"`
ViaAirport string `json:"via_airport"`
Carousel string `json:"carousel"`
Terminal string `json:"terminal"`
Aircraft string `json:"aircraft"`
FlightStatus FlightStatus `json:"flight_status"`
DisplayedMasterFlightCodes string `json:"displayed_master_flight_codes"`
Gate string `json:"gate"`
CheckinDesks string `json:"checkin_desks"`
DepartureBool int `json:"departure_bool"`
Company string `json:"company"`
AirportCode string `json:"airport_code"`
OriginCountry string `json:"origin_country"`
AirportCodeDestination string `json:"airport_code_destination"`
FlightType FlightType `json:"flight_type"`
FlightDurationMinutes int `json:"flight_duration_minuts"`
ControleDouane int `json:"controle_douane"`
GateWalkTime int `json:"gate_walk_time"`
DelayMinutes int `json:"delay_minuts"`
FlightID int `json:"flight_id"`
AircraftID int `json:"aircraft_id"`
NextPublicAdvice GVATime `json:"next_public_advice"`
ScheduledDeparture GVATime `json:"scheduled_departure"`
ScheduledArrival GVATime `json:"scheduled_arrival"`
Departure GVATime `json:"departure"`
Arrival GVATime `json:"arrival"`
PublicArrival GVATime `json:"public_arrival"`
PublicDeparture GVATime `json:"public_departure"`
Airborn GVATime `json:"airborn"`
FirstPriorityBaggage GVATime `json:"first_priority_baggage"`
DepartureFromPreviousAirport GVATime `json:"departure_from_previous_airport"`
EstimatedLanding GVATime `json:"estimated_landing"`
EstimatedBoarding GVATime `json:"estimated_boarding"`
ScheduledFlight GVATime `json:"scheduled_flight"`
AircraftRegistration string `json:"aircraft_registration"`
State string `json:"state"`
LastUpdate GVATime `json:"last_update"`
AirportCity string `json:"airport_city"`
}