-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathflightstatus.go
86 lines (77 loc) · 1.7 KB
/
flightstatus.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
package main
import (
"strings"
"github.com/jwalton/gchalk"
)
// FlightStatus is a dummy struct to allow Stringer() redef
type FlightStatus struct {
status string
}
// "Took off", "Cancelled, "Departed", "Boarding", "Go to gate"
func (me *FlightStatus) String() string {
switch status := me.status; status {
case "Boarding":
return gchalk.WithBrightMagenta().Bold(status)
case "Go to gate":
return gchalk.WithBrightCyan().Bold(status)
case "Arrived":
return gchalk.Green(status)
case "Departed":
return gchalk.Blue(status)
case "Delayed":
return gchalk.Yellow(status)
case "Next Info":
return gchalk.WithWhite().BgYellow("Delayed")
case "Cancelled":
return gchalk.WithWhite().WithBgRed().Bold(status)
default:
return gchalk.WithGreen().Bold(status)
}
}
// UnmarshalJSON is a custom parser for flight status
func (me *FlightStatus) UnmarshalJSON(b []byte) (err error) {
s := strings.Trim(string(b), "\"")
if s == "null" {
me.status = ""
return
}
me.status = s
return
}
type FlightType uint
const (
FlightTypeSchengen = iota
FlightTypeInternational
FlightTypeFrance
FlightTypeOther
FlightTypeUnknown
)
func (me *FlightType) String() string {
switch *me {
case FlightTypeSchengen:
return "Schengen"
case FlightTypeInternational:
return "International"
case FlightTypeFrance:
return "France"
case FlightTypeOther:
return "Other" // Not clear
default:
return "Unknown"
}
}
func (me *FlightType) UnmarshalJSON(b []byte) (err error) {
switch strings.Trim(string(b), "\"") {
case "S":
*me = FlightTypeSchengen
case "I":
*me = FlightTypeInternational
case "F":
*me = FlightTypeFrance
case "O":
*me = FlightTypeOther
case "null":
*me = FlightTypeUnknown
}
return
}