Commit 1e5bd626 authored by Aksel Baardsen's avatar Aksel Baardsen
Browse files

added comments for all handlers

parent 2817db40
......@@ -8,6 +8,7 @@ import (
"net/http"
)
// handles requests for /country/
func Chandler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
limit := r.FormValue("limit") // gets the limit, if specified
......@@ -17,6 +18,7 @@ func Chandler(w http.ResponseWriter, r *http.Request) {
limit = "5"
}
// gets a country-struct containing data, or error
country, err := pkg.GetCountryByCode(vars["country_identifier"], limit)
if err == nil {
......
......@@ -7,10 +7,14 @@ import (
"net/http"
)
// handles requests for /diag/
func Dhandler(w http.ResponseWriter, r *http.Request) {
var diagnostics pkg.Diag
// fills in the diagnostics-var
err := pkg.GetDiag(&diagnostics)
// if error was encountered: print error, else: return diagnostics
if err != nil {
http.Error(w, err.Error(), http.StatusBadGateway)
} else {
......
......@@ -8,10 +8,14 @@ import (
"net/http"
)
// handles /species/
func Shandler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
// fills in a species-struct
specie, err := pkg.GetSpecies(vars["speciesKey"])
// if no error: print correct json, else: send correct errormessage/header
if err == nil {
w.Header().Set("Content-Type", "application/json")
err = json.NewEncoder(w).Encode(&specie)
......
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