diff --git a/main.go b/main.go new file mode 100644 index 0000000000000000000000000000000000000000..55ebb52f82cd8a588c9eda215c0ce694bff49491 --- /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()) + } + +}