-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
52 lines (43 loc) · 862 Bytes
/
main.go
File metadata and controls
52 lines (43 loc) · 862 Bytes
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
package main
import (
"fmt"
"log"
"net/http"
)
type tokenType uint8
const (
STRONG_WIND tokenType = iota
LOW_VIZ
LOW_CLOUDBASE
CONVECTIVE_CLOUDS
WEATHER
)
type alert struct {
startIndex int
endIndex int
token tokenType
}
type METAR struct {
metarText string
alerts []alert
}
func main() {
http.HandleFunc("/", metarRequest)
log.Fatal(http.ListenAndServe(":8080", nil))
}
func metarRequest(w http.ResponseWriter, r *http.Request) {
query := r.URL.Query()
icaoCode := query.Get("icao")
metar := retrieveMETAR(icaoCode)
description := retrieveAirportName(icaoCode)
m := newMETAR(metar)
m.markWind()
m.markVisibility()
m.markCloudbase()
m.markCriticalWeather()
m.markConvectiveClouds()
_, err := fmt.Fprint(w, parseMetarTemplate(description, m.colorAreas("<b>", "</b>")))
if err != nil {
fmt.Println(err.Error())
}
}