From e6ce77dc0608377a07871f3af747a1b02879c437 Mon Sep 17 00:00:00 2001 From: Andreas Magnarson Nypan <andrenyp@stud.ntnu.no> Date: Fri, 7 Mar 2025 13:08:00 +0000 Subject: [PATCH] Upload New File --- main.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 main.go diff --git a/main.go b/main.go new file mode 100644 index 0000000..55ebb52 --- /dev/null +++ b/main.go @@ -0,0 +1,31 @@ +package main + +import ( + "CountryAPI/handlers" + "CountryAPI/utils" + "log" + "net/http" + "os" + "time" +) + +func main() { + utils.StartTime = time.Now() //starting the uptime of the application + port := os.Getenv("PORT") + if port == "" { + log.Println("$PORT has not been set. Default: 8080") + port = "8080" + } + + http.HandleFunc("/countryinfo/v1/info/", handlers.HandleCountryInfo) + http.HandleFunc("/countryinfo/v1/population/", handlers.HandlePopulation) + http.HandleFunc("/countryinfo/v1/status/", handlers.HandleStatus) + + log.Println("Running on port", port) + + err := http.ListenAndServe(":"+port, nil) + if err != nil { + log.Fatal(err.Error()) + } + +} -- GitLab