From 777eac017ef715c3ea448c955fd016a45c4a9e07 Mon Sep 17 00:00:00 2001 From: Mathilde Hertaas <maimh@stud.ntnu.no> Date: Thu, 6 Mar 2025 13:13:45 +0100 Subject: [PATCH] updatet infromation in README and information on homepage --- README.md | 2 ++ handelers/homeHandler.go | 9 +++++++-- handelers/konstanter.go | 6 +++++- main.go | 4 ++-- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 3295215..677c3ee 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,7 @@ Henter informasjon om et land basert på en 2-bokstavs landkode (ISO 3166-2). ```sh http://localhost:8080/countryinfo/v1/info/{country_code}{?limit=10} ``` +* limit er en valgfri parameter som gir en begrenisng på antall byer som vises med valgt land (Default er 10 stykker) * Metode: GET * Eksempel: http://localhost:8080/countryinfo/v1/info/NO?limit=4 @@ -40,6 +41,7 @@ Hente populasjonsdata om et land basert på en 2-bokstavs landkode (ISO 3166-2). ```sh http://localhost:8080/countryinfo/v1/population/{country_code}{?startyear-endYear} ``` +* startYear-endYear er en valfri parameter som gir begreninger på spesifikke år du får populasjonsdata fra (Default er alle tilgjengelige år) * Metode: GET * Eksempel: http://localhost:8080/population/NO?limit=2010-2015 diff --git a/handelers/homeHandler.go b/handelers/homeHandler.go index be20d26..4976d27 100644 --- a/handelers/homeHandler.go +++ b/handelers/homeHandler.go @@ -10,17 +10,22 @@ import ( func HomeHandler(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") response := map[string]interface{}{ - "WELCOME": "Welcome to the Country Info API", + WELCOME: WELCOME_MESSAGE, "endpoints": map[string]interface{}{ "Get Country Info": map[string]string{ "Description": "Get country details including cities, population, and more.", - "URL Format": "http://localhost:8080/countryinfo/v1/info/{country_code}{?limit=10}", + "URL Format": "http://localhost:8080/countryinfo/v1/info/{ISO_3166-2_country_code}{?limit=10}", "Example": "http://localhost:8080/countryinfo/v1/info/NO?cities=5", }, "Get status info" : map[string]string{ "Description" : "Get information about the API statuses", "URL" : "http://localhost:8080/status/", }, + "Get population info" : map[string]string{ + "Description" : "Get information about countries and their population", + "URL" : "http://localhost:8080/countryinfo/v1/population/{ISO_3166-2_country_code}{?startYear-endYear}", + "Example": "http://localhost:8080/countryinfo/v1/population/NO?2010-2015}", + }, }, } diff --git a/handelers/konstanter.go b/handelers/konstanter.go index 4afe3be..5f9e9a6 100644 --- a/handelers/konstanter.go +++ b/handelers/konstanter.go @@ -10,4 +10,8 @@ const SLASH_DEFAULT = "/" //ERRORS //Terminal info -const RUNNING_ON_PORT = "" \ No newline at end of file +const RUNNING_ON_PORT = "" + +//User information +const WELCOME = "WELCOME" +const WELCOME_MESSAGE = "Welcome to the Country Info API" \ No newline at end of file diff --git a/main.go b/main.go index d1d4718..364c129 100644 --- a/main.go +++ b/main.go @@ -19,8 +19,8 @@ func main() { http.HandleFunc(handelers.INFO_DEFAULT, handelers.CountryInfoHandler) http.HandleFunc(handelers.POPULATION_DEFAULT, handelers.PopulationHandler) - if err := http.ListenAndServe(":8080", nil); err != nil { fmt.Printf("Server failed to start: %s\n", err) } -} \ No newline at end of file +} + -- GitLab