returnnil,fmt.Errorf("country not found for code: %s",countryCode)
}
// Returner det første elementet i listen (siden vi forventer bare ett treff)
return&countries[0],nil
}
funchandler(whttp.ResponseWriter,r*http.Request){
fmt.Fprintf(w,"Hello, Cloud Technologies!")
// Hent landkode fra path (for eksempel "/countryinfo/v1/info/NO")
parts:=strings.Split(r.URL.Path,"/")
iflen(parts)<5{
http.Error(w,"Invalid request format. Please use the format /countryinfo/v1/info/{countryCode}. Example: /countryinfo/v1/info/NO",http.StatusBadRequest)
return
}
countryCode:=parts[4]// Landkoden er den 5. delen av pathen (fra 0)
// Hent data fra API ved landkode
country,err:=getCountryDataByCode(countryCode)
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)