From f45119a5c7acba77eb120d61eac7fb5421034e49 Mon Sep 17 00:00:00 2001 From: Mathilde Hertaas <maimh@stud.ntnu.no> Date: Thu, 6 Mar 2025 21:05:11 +0100 Subject: [PATCH] translated README to english --- README.md | 49 +++++++++++++++++----------------- handelers/constants.go | 3 --- handelers/populasjonhandler.go | 4 +-- 3 files changed, 25 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index 89953c6..27b3ac0 100644 --- a/README.md +++ b/README.md @@ -1,52 +1,51 @@ # Assignment 1 -## Kjøre koden -Koden kjøres ved å skrive følgende kommando i terminalen: +## Running the code +The code is run by typing the following command in the terminal: ```sh go run main.go ``` -Når serveren starter, kan du åpne nettleseren og navigere til: +When the server starts, you can open your browser and navigate to: * http://localhost:8080/ - - Dette er hjemmesiden til API-et. - - Når serveren startes er det hit du eventuelt blir sendt automatisk -* Alternativt kan du bruke en av endepunktene beskrevet nedenfor for å navigere applikasjonen + - This is the homepage of the API. + - When the server starts, you may be automatically redirected here. +* Alternatively, you can use one of the endpoints described below to navigate the application. +## Homepage (/) +When you open the API without specific requests (http://localhost:8080/), you will receive a JSON response with information on how to use the API. -## Hjemmeside (/) -Når du åpner API-et uten spesifikke forespørsler (http://localhost:8080/), vil du få en JSON-respons med informasjon om hvordan du bruker API-et. +Here you will find information about the three available endpoints: +1. info - Retrieves general information about a country. +2. population - Retrieves population data for a country. +3. status - Displays the status of the API. -Her får du informasjon om de tre tilgjengelige endepunktene: -1. info - Henter generell informajson om et land. -2. populasjon - Henter populasjonsdata for et land. -3. status - Viser status for API-et. +Additionally, examples of how to send requests to the various endpoints are shown. -I tillegg vises eksempler på hvordan du kan sende forespørsler til de ulike endepunktene. - -## Endepunkter +## Endpoint ### info -Henter informasjon om et land basert på en 2-bokstavs landkode (ISO 3166-2). +Retrieves information about a country based on a 2-letter country code (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 +* limit is an optional parameter that specifies the maximum number of cities to display with the selected country (Default is 10). +* Method: GET +* Example: http://localhost:8080/countryinfo/v1/info/NO?limit=4 -#### populasjon -Hente populasjonsdata om et land basert på en 2-bokstavs landkode (ISO 3166-2). +#### population +Retrieves population data for a country based on a 2-letter country code (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/countryinfo/v1/population/NO?limit=2010-2015 +* startYear-endYear is an optional parameter that limits the specific years from which you retrieve population data (Default is all available years). +* Method: GET +* Example: http://localhost:8080/countryinfo/v1/population/NO?limit=2010-2015 ### status -Viser status for de eksterne API-ene, versjon og applikasjonens oppetid. +Displays the status of the external APIs, version, and the application's uptime. ```sh http://localhost:8080/countryinfo/v1/status diff --git a/handelers/constants.go b/handelers/constants.go index def4dd1..d3c1725 100644 --- a/handelers/constants.go +++ b/handelers/constants.go @@ -11,9 +11,6 @@ const SLASH_DEFAULT = "/" const CITIES_ERROR = "error retrieving cities, status code: " const CITIES_ERROR2 = "no cities found for country %s" -//Terminal info -const RUNNING_ON_PORT = "" - //User information home page const WELCOME_MESSAGE = "Welcome to the Country Info API" const INFO_DESCRIPTION = "Provides information about a specific country. " diff --git a/handelers/populasjonhandler.go b/handelers/populasjonhandler.go index eedb0c2..2b7d7e0 100644 --- a/handelers/populasjonhandler.go +++ b/handelers/populasjonhandler.go @@ -14,7 +14,7 @@ var isoAlpha2ToAlpha3 = make(map[string]string) // Henter befolkningsdata fra eksternt API func fetchPopulationData() (*PopulationResponse, error) { - url := "https://countriesnow.space/api/v0.1/countries/population" + url := "http://129.241.150.113:3500/api/v0.1/countries/population" resp, err := http.Get(url) if err != nil { return nil, err @@ -37,7 +37,6 @@ func fetchPopulationData() (*PopulationResponse, error) { return &data, nil } -// Henter befolkningsdata for et spesifikt land og filtrerer etter år func getPopulationForCountry(alpha2Code string, startYear, endYear int) (*PopulationAPIResponse, error) { data, err := fetchPopulationData() if err != nil { @@ -69,7 +68,6 @@ func getPopulationForCountry(alpha2Code string, startYear, endYear int) (*Popula var total int count := 0 - for _, stk := range countryData.PopulationCounts { if (startYear == 0 || stk.Year >= startYear) && (endYear == 0 || stk.Year <= endYear) { filteredValues = append(filteredValues, stk) -- GitLab