diff --git a/assignment1 b/assignment1 index 5653d5158b4d42079a978057f70d3f2b45541cbe..6a9967d1f9ae8ffd03ee94c38ae72983f9075b3a 100755 Binary files a/assignment1 and b/assignment1 differ diff --git a/webapp.go b/webapp.go index 782e6cabf1602ff64c0709f95d03091fbb2084ee..a8d9dc7daf8770dc4b012775ae2d6aeaababad76 100644 --- a/webapp.go +++ b/webapp.go @@ -18,30 +18,29 @@ type CntrInfo struct { Flag string `json:flag` Name string `json:"name"` //"country":"norway" CountryCode string `json:"alpha2Code"`//"NO" - SpeciesName string `json:"species"` - SpeciesKey int64 `json:"speciesKey"` + } //Our json slice response -type SpeciesResponse struct { - SSpeciesName [] SpeciesInfo //The name of the other struct - SSpeciesKey [] SpeciesKeyBody `json:"speciesKey"` +type CollectionFromReq struct { + Count int `json:"count"` + Collection []Result `json:"result"` } // Info about each specie -type SpeciesInfo struct { - +type Result struct { + Species string `json:"species"` + SpeciesKey int `json:"speciesKey"` } -// Info about each key +/* Info about each key type SpeciesKeyBody struct{ - key int Kingdom string family string year string //Hint: For the year, check the /species/{key}/name path for a given key. - } +*/ //Should return the name Norway func getCountryName(cn string) (string, string, string) { @@ -91,8 +90,8 @@ func getCountryName(cn string) (string, string, string) { return ci.Name, ci.CountryCode, ci.Flag } - -func getSpeciesByCountry(Ccode string) (string, int64){ +// Should return species in exa: norway and key +func getSpeciesByCountry(Ccode string) (string, int){ url := apiRootSpeciesInCountry + Ccode resp, err := http.Get(url) if err !=nil { @@ -105,15 +104,20 @@ func getSpeciesByCountry(Ccode string) (string, int64){ //Pointer to struct // will this also point to the slices and what the slices contain?? // Points to struct containing two slices of struct - ci := &CntrInfo{} + crf :=&CollectionFromReq{} //resp.Body JSON from API //Decode resp.Body and put into .decode(HERE) //We need the resp.Body to be slices - json.NewDecoder(resp.Body).Decode(ci) - fmt.Println("after json decoder",ci) + json.NewDecoder(resp.Body).Decode(crf) + + fmt.Println("after json decoder",resp.Body) - return ci.SpeciesName, ci.SpeciesKey + for i := 0; i < crf.Count; i++ { + + return crf.Collection[i].Species, crf.Collection[i].SpeciesKey + } + return "", 0 }