-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHandlers.go
More file actions
59 lines (45 loc) · 1.4 KB
/
Handlers.go
File metadata and controls
59 lines (45 loc) · 1.4 KB
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
package main
import (
"encoding/json"
"net/http"
"strings"
"github.com/gorilla/mux"
)
func Index(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
w.WriteHeader(http.StatusOK)
allAirlines := GetAllRows("airline")
if err := json.NewEncoder(w).Encode(allAirlines); err != nil {
panic(err)
}
}
func Show(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
airlineCode := strings.Trim(vars["airlineCode"], " ")
airlineInfo := GetRows("airline", "IATA", airlineCode)
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
w.WriteHeader(http.StatusOK)
if err := json.NewEncoder(w).Encode(airlineInfo); err != nil {
panic(err)
}
}
func ShowById(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
id := strings.Trim(vars["Id"], " ")
airlineInfo := GetRows("airline", "Id", id)
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
w.WriteHeader(http.StatusOK)
if err := json.NewEncoder(w).Encode(airlineInfo); err != nil {
panic(err)
}
}
func Country(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
country := strings.Trim(vars["country"], " ")
airlineInfo := GetRows("airline", "Country", country)
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
w.WriteHeader(http.StatusOK)
if err := json.NewEncoder(w).Encode(airlineInfo); err != nil {
panic(err)
}
}