Skip to content
Snippets Groups Projects
Commit 5795887b authored by andmag's avatar andmag
Browse files

species and speciesKey list

parent 5be4f0af
Branches
No related tags found
No related merge requests found
......@@ -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())
}
}
*/
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment