// Hent landkode fra path (for eksempel "/countryinfo/v1/info/NO")
// Hent landkode fra path
parts:=strings.Split(r.URL.Path,"/")
parts:=strings.Split(r.URL.Path,"/")
iflen(parts)<5{
iflen(parts)<5{
http.Error(w,"Invalid format. Please use the format /countryinfo/v1/info/{countryCode}. Example: /countryinfo/v1/info/NO",http.StatusBadRequest)
http.Error(w,"Invalid format. Please use the format /countryinfo/v1/info/{countryCode}{?limit=10}. Example: /countryinfo/v1/info/NO",http.StatusBadRequest)
return
return
}
}
countryCode:=parts[4]// Landkoden er den 5. delen av pathen (fra 0)
countryCode:=parts[4]// Landkoden er den 5. delen av pathen (fra 0)
// Hent data fra API ved landkode
// Hent data fra API ved landkode
//country inneholder data om alt går bra
country,err:=getCountryDataByCode(countryCode)
country,err:=getCountryDataByCode(countryCode)
//err inneholder feil hvis noe går galt, ikke finner landkode
iferr!=nil{
iferr!=nil{
http.Error(w,fmt.Sprintf("Error retrieving data for country code: %s. Check if the country code is correct.\nExample: /countryinfo/v1/info/NO",err.Error()),http.StatusInternalServerError)
http.Error(w,fmt.Sprintf(
return
"Error retrieving data for country code: %s. Check if the country code is correct.\nExample: /countryinfo/v1/info/NO\nError: %s",