-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathmain.go
80 lines (63 loc) · 2.45 KB
/
main.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
package main
import (
"encoding/json"
"net/http"
)
type Airport struct {
Name string `json:"name"`
City string `json:"city"`
IATA string `json:"iata"`
ImageURL string `json:"image_url"`
}
type AirportV2 struct {
Airport
RunwayLength int `json:"runway_length"`
}
// Mock data for airports in Bangladesh
var airports = []Airport{
{"Hazrat Shahjalal International Airport", "Dhaka", "DAC", "https://storage.googleapis.com/bd-airport-data/dac.jpg"},
{"Shah Amanat International Airport", "Chittagong", "CGP", "https://storage.googleapis.com/bd-airport-data/cgp.jpg"},
{"Osmani International Airport", "Sylhet", "ZYL", "https://storage.googleapis.com/bd-airport-data/zyl.jpg"},
}
// Mock data for airports in Bangladesh (with runway length for V2)
var airportsV2 = []AirportV2{
{Airport{"Hazrat Shahjalal International Airport", "Dhaka", "DAC", "https://storage.googleapis.com/bd-airport-data/dac.jpg"}, 3200},
{Airport{"Shah Amanat International Airport", "Chittagong", "CGP", "https://storage.googleapis.com/bd-airport-data/cgp.jpg"}, 2900},
{Airport{"Osmani International Airport", "Sylhet", "ZYL", "https://storage.googleapis.com/bd-airport-data/zyl.jpg"}, 2500},
}
// HomePage handler
func HomePage(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write([]byte("Status: OK"))
}
// Airports handler for the first endpoint
func Airports(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(airports)
}
// AirportsV2 handler for the second version endpoint
func AirportsV2(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(airportsV2)
}
// ##############################
// ## TODO: Edit this function ##
// ##############################
// UpdateAirportImage handler for updating airport images
func UpdateAirportImage(w http.ResponseWriter, r *http.Request) {
// Parse the request body to get the airport name and image data
// Find the airport by name
// Initialize GCS client
// Upload image to GCS and update the airport's image URL
// Respond with success/failure
}
func main() {
// Setup routes
http.HandleFunc("/", HomePage)
http.HandleFunc("/airports", Airports)
http.HandleFunc("/airports_v2", AirportsV2)
// TODO: complete the UpdateAirportImage handler function
http.HandleFunc("/update_airport_image", UpdateAirportImage)
// Start the server
http.ListenAndServe(":8080", nil)
}