diff --git a/country.go b/country.go index a33ed32a7ab90906065afc4f9f7cfc37fe973cb5..c9007584019dcb5e2a065b899c6e223f91258a17 100644 --- a/country.go +++ b/country.go @@ -50,7 +50,6 @@ func HandlerCountry(w http.ResponseWriter, r *http.Request) { } -/* // HandlerOnlySpecies skjdfhkshfkl func HandlerOnlySpecies(w http.ResponseWriter, r *http.Request) { @@ -58,6 +57,12 @@ func HandlerOnlySpecies(w http.ResponseWriter, r *http.Request) { parts := strings.Split(r.URL.Path, "/") + if len(parts) != 5 || parts[1] != "conservation" || parts[2] != "v1" || parts[3] != "spec" || parts[4] == "" { + status := http.StatusBadRequest + http.Error(w, "Expecting format /conservation/v1/spec/'alphacode'", status) + return + } + APIURL += parts[4] http.Header.Add(w.Header(), "content-type", "application/json") @@ -75,11 +80,46 @@ func HandlerOnlySpecies(w http.ResponseWriter, r *http.Request) { defer resp.Body.Close() - var species []SpeciesByCountry - //species := []SpeciesByCountry{} - //mySpeciesList := make([]SBCList, 0) - json.NewDecoder(resp.Body).Decode(&species) - json.NewEncoder(w).Encode(species) + type Result Results + + var name = &Result{} + + //v, _ := ioutil.ReadAll(resp.Body) + + //fmt.Println("Body: ", string(v)) + + err2 := json.NewDecoder(resp.Body).Decode(name) + if err2 != nil { + fmt.Println("Error", err2.Error()) + } + + var spec []string + var specKey []int + + for k, v := range name.Res1 { + fmt.Println(k) + + fmt.Println(v.Species) + spec = append(spec, v.Species) + specKey = append(specKey, v.SpeciesKey) + fmt.Println(v.SpeciesKey) + /*for k1, v1 := range v { + fmt.Println(k1, v1) + }*/ + fmt.Println(v) + + } + + fmt.Println(spec) + + result := Results2{} + + result.Res2 = spec + result.Res3 = specKey + + err3 := json.NewEncoder(w).Encode(result) + if err3 != nil { + fmt.Println("error2", err3.Error()) + } } -*/