From c1c7aa0244bcbdbee4dba630dbf63e1be3676121 Mon Sep 17 00:00:00 2001 From: Mathilde Hertaas <maimh@stud.ntnu.no> Date: Thu, 6 Mar 2025 13:00:39 +0100 Subject: [PATCH] added constant to main class urls --- handelers/konstanter.go | 15 +++++++++++---- handelers/strukter.go | 10 ++++------ main.go | 10 ++++------ 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/handelers/konstanter.go b/handelers/konstanter.go index 9f88f55..4afe3be 100644 --- a/handelers/konstanter.go +++ b/handelers/konstanter.go @@ -1,6 +1,13 @@ package handelers -const HOMEPAGE_DEFAULT = "http://localhost:8080/" //url til hjemmeside -const INFO_DEFAULT = "http://localhost:8080/countryinfo/vi/info/" // url info for brukerspesifikasjon -const POPULATION_DEFAULT = "" -const STATUS_DEFAULT = "" \ No newline at end of file +//URL +const HOMEPAGE_DEFAULT = "http://localhost:8080" +const INFO_DEFAULT = "/countryinfo/vi/info/" +const POPULATION_DEFAULT = "/population/" +const STATUS_DEFAULT = "/status/" +const SLASH_DEFAULT = "/" + +//ERRORS + +//Terminal info +const RUNNING_ON_PORT = "" \ No newline at end of file diff --git a/handelers/strukter.go b/handelers/strukter.go index 4a97f3b..9613329 100644 --- a/handelers/strukter.go +++ b/handelers/strukter.go @@ -1,6 +1,5 @@ package handelers - type Flags struct{ PNG string `json:"png"` } @@ -19,12 +18,11 @@ type CountryInfo struct { Flags Flags `json:"flags"` } -type CityInfo struct { - Cities []string `json:"cities"` -} - +//type CityInfo struct { +// Cities []string `json:"cities"` +//} -// Struktur for kombinert respons +// Struktur for kombinert respons i info type CombinedInfo struct { Name string `json:"name"` Continents []string `json:"continenents"` diff --git a/main.go b/main.go index ee53077..d1d4718 100644 --- a/main.go +++ b/main.go @@ -9,19 +9,17 @@ import ( var serviceStartTime time.Time - func main() { serviceStartTime = time.Now() - http.HandleFunc("/status/", func(w http.ResponseWriter, r *http.Request) { + http.HandleFunc(handelers.STATUS_DEFAULT, func(w http.ResponseWriter, r *http.Request) { handelers.DiagnosticsHandler(w, r, serviceStartTime) }) - http.HandleFunc("/", handelers.HomeHandler) - http.HandleFunc("/countryinfo/v1/info/", handelers.CountryInfoHandler) - http.HandleFunc("/population/", handelers.PopulationHandler) + http.HandleFunc(handelers.SLASH_DEFAULT, handelers.HomeHandler) + http.HandleFunc(handelers.INFO_DEFAULT, handelers.CountryInfoHandler) + http.HandleFunc(handelers.POPULATION_DEFAULT, handelers.PopulationHandler) - fmt.Println("Server running on port 8080...") if err := http.ListenAndServe(":8080", nil); err != nil { fmt.Printf("Server failed to start: %s\n", err) } -- GitLab