Commit 7ba9ca1d authored by Aksel Baardsen's avatar Aksel Baardsen
Browse files

removed unessecary comments&whitespace

parent 12827928
......@@ -15,6 +15,7 @@ func main() {
r := mux.NewRouter()
c := r.PathPrefix("/conservation/v1").Methods("GET").Subrouter()
// two handlerpaths makes sure that the caller does not HAVE to specify limit
c.Path("/country/{country_identifier:[a-zA-Z][a-zA-Z]}").
Queries("limit", "{limit}").
HandlerFunc(cHandler).
......@@ -28,31 +29,17 @@ func main() {
c.Path("/diag/").
HandlerFunc(dHandler)
//c.HandleFunc("/country/{country_identifier:[a-zA-Z][a-zA-Z]}", cHandler).Queries("limit", "{limit}")
//c.HandleFunc("/species/{speciesKey}", sHandler)
//c.HandleFunc("/diag/", dHandler)
http.Handle("/", r)
log.Fatal(http.ListenAndServe(":5000", nil))
}
/*
func helloHandle(w http.ResponseWriter, r *http.Request) {
_, _ = fmt.Fprint(w, "Heisann!")
}
*/
func dHandler(w http.ResponseWriter, r *http.Request) {
//_, _ = fmt.Fprintln(w, "aiaiai")
var d pkg.Diag
pkg.GetDiag(&d)
marsh, _ := json.Marshal(d)
fmt.Fprintln(w, string(marsh))
}
func cHandler(w http.ResponseWriter, r *http.Request) {
......@@ -66,17 +53,13 @@ func cHandler(w http.ResponseWriter, r *http.Request) {
c, _ := json.Marshal(country)
fmt.Fprintln(w, string(c))
}
func sHandler(w http.ResponseWriter, r *http.Request) {
//_, _ = fmt.Fprintln(w, "aiaiai")
vars := mux.Vars(r)
specie := pkg.GetSpecies(vars["speciesKey"])
s, _ := json.Marshal(specie)
fmt.Fprintln(w, string(s))
}
\ No newline at end of file
......@@ -9,13 +9,11 @@ const countryApi = "https://restcountries.eu/rest/v2/alpha/"
const occurrenceApi = "http://api.gbif.org/v1/occurrence/search?"
type Country struct {
Code string `json:"alpha2Code"`
CountryName string `json:"name"`
CountryFlag string `json:"flag"`
Species []string `json:"species"`
SpeciesKey []int `json:"speciesKey"`
}
type Response struct {
......@@ -23,11 +21,9 @@ type Response struct {
}
type Results struct {
Species string `json:"species"`
SpeciesKey int `json:"speciesKey"`
CountryCode string `json:"countryCode"`
}
func GetCountryByCode(code, limit string) Country {
......
......@@ -7,7 +7,6 @@ import (
)
func getString(url string) string {
resp, err:= http.Get(url)
if err != nil {
log.Fatal(err)
......
......@@ -8,7 +8,6 @@ import (
const speciesApi = "http://api.gbif.org/v1/species/"
type Specie struct {
Key int `json:"key"`
Kingdom string `json:"kingdom"`
Phylum string `json:"phylum"`
......@@ -19,11 +18,9 @@ type Specie struct {
ScientificName string `json:"scientificName"`
CanonicalName string `json:"canonicalName"`
Year string `json:"year"`
}
func GetSpecies(key string) Specie {
var specie Specie
url := speciesApi + key
sBody := getString(url)
......@@ -39,22 +36,5 @@ func GetSpecies(key string) Specie {
log.Fatal(err)
}
/*
resp, err:= http.Get(speciesApi + key)
if err != nil {
log.Fatal(err)
}
specie := &Specie{}
err = json.NewDecoder(resp.Body).Decode(specie)
if err != nil {
// handle pls
}
defer resp.Body.Close()
*/
return specie
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment