Skip to content
Snippets Groups Projects
Commit 7df4a6b1 authored by Mathilde Hertaas's avatar Mathilde Hertaas
Browse files

separated populasion class and added constant class

parent f6bf6390
Branches
No related tags found
No related merge requests found
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
...@@ -9,42 +9,6 @@ import ( ...@@ -9,42 +9,6 @@ import (
"strings" "strings"
) )
// responsstruktur for befolkningsdata
type PopulationResponse struct {
Error bool `json:"error"`
Msg string `json:"msg"`
Data []Country `json:"data"`
}
// land og dens befolkningsdata
type Country struct {
Name string `json:"country"`
Code string `json:"iso3"` // Trebokstavskode (ISO 3166-1 alpha-3)
PopulationCounts []PopulationCount `json:"populationCounts"`
}
// befolkningsdate for et bestemt år (brukes i den endelige repsonsen under values)
type PopulationCount struct {
Year int `json:"year"`
Value int `json:"value"`
}
// Responsstruktur for vårt API(det som vises på skjerm)
type PopulationAPIResponse struct {
Name string `json:"land"`
Gjennomsnitt int `json:"gjennomsnittlig populasjon"`
Values []PopulationCount `json:"årlige populasjoner"`
}
// ISO 3166-1 alpha-2 til alpha-3 landkoder // ISO 3166-1 alpha-2 til alpha-3 landkoder
var isoAlpha2ToAlpha3 = make(map[string]string) var isoAlpha2ToAlpha3 = make(map[string]string)
...@@ -129,9 +93,6 @@ func getPopulationForCountry(alpha2Code string, startYear, endYear int) (*Popula ...@@ -129,9 +93,6 @@ func getPopulationForCountry(alpha2Code string, startYear, endYear int) (*Popula
}, nil }, nil
} }
func PopulationHandler(w http.ResponseWriter, r *http.Request) { func PopulationHandler(w http.ResponseWriter, r *http.Request) {
// r.URL.Path er den fulle URL som ble sendt til serveren altså /population/NO // r.URL.Path er den fulle URL som ble sendt til serveren altså /population/NO
// deretter fjerner den /population/ så vi sitter igjen med NO // deretter fjerner den /population/ så vi sitter igjen med NO
......
...@@ -35,3 +35,31 @@ type CombinedInfo struct { ...@@ -35,3 +35,31 @@ type CombinedInfo struct {
Capital string `json:"capital"` Capital string `json:"capital"`
Cities string `json:"cities"` Cities string `json:"cities"`
} }
// responsstruktur for befolkningsdata
type PopulationResponse struct {
Error bool `json:"error"`
Msg string `json:"msg"`
Data []Country `json:"data"`
}
// land og dens befolkningsdata
type Country struct {
Name string `json:"country"`
Code string `json:"iso3"` // Trebokstavskode (ISO 3166-1 alpha-3)
PopulationCounts []PopulationCount `json:"populationCounts"`
}
// befolkningsdate for et bestemt år (brukes i den endelige repsonsen under values)
type PopulationCount struct {
Year int `json:"year"`
Value int `json:"value"`
}
// Responsstruktur for vårt API(det som vises på skjerm)
type PopulationAPIResponse struct {
Name string `json:"land"`
Gjennomsnitt int `json:"gjennomsnittlig populasjon"`
Values []PopulationCount `json:"årlige populasjoner"`
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment