Skip to content
Snippets Groups Projects
Commit 1e5bd626 authored by Aksel Baardsen's avatar Aksel Baardsen
Browse files

added comments for all handlers

parent 2817db40
Branches
No related tags found
No related merge requests found
...@@ -8,6 +8,7 @@ import ( ...@@ -8,6 +8,7 @@ import (
"net/http" "net/http"
) )
// handles requests for /country/
func Chandler(w http.ResponseWriter, r *http.Request) { func Chandler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r) vars := mux.Vars(r)
limit := r.FormValue("limit") // gets the limit, if specified limit := r.FormValue("limit") // gets the limit, if specified
...@@ -17,6 +18,7 @@ func Chandler(w http.ResponseWriter, r *http.Request) { ...@@ -17,6 +18,7 @@ func Chandler(w http.ResponseWriter, r *http.Request) {
limit = "5" limit = "5"
} }
// gets a country-struct containing data, or error
country, err := pkg.GetCountryByCode(vars["country_identifier"], limit) country, err := pkg.GetCountryByCode(vars["country_identifier"], limit)
if err == nil { if err == nil {
......
...@@ -7,10 +7,14 @@ import ( ...@@ -7,10 +7,14 @@ import (
"net/http" "net/http"
) )
// handles requests for /diag/
func Dhandler(w http.ResponseWriter, r *http.Request) { func Dhandler(w http.ResponseWriter, r *http.Request) {
var diagnostics pkg.Diag var diagnostics pkg.Diag
// fills in the diagnostics-var
err := pkg.GetDiag(&diagnostics) err := pkg.GetDiag(&diagnostics)
// if error was encountered: print error, else: return diagnostics
if err != nil { if err != nil {
http.Error(w, err.Error(), http.StatusBadGateway) http.Error(w, err.Error(), http.StatusBadGateway)
} else { } else {
......
...@@ -8,10 +8,14 @@ import ( ...@@ -8,10 +8,14 @@ import (
"net/http" "net/http"
) )
// handles /species/
func Shandler(w http.ResponseWriter, r *http.Request) { func Shandler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r) vars := mux.Vars(r)
// fills in a species-struct
specie, err := pkg.GetSpecies(vars["speciesKey"]) specie, err := pkg.GetSpecies(vars["speciesKey"])
// if no error: print correct json, else: send correct errormessage/header
if err == nil { if err == nil {
w.Header().Set("Content-Type", "application/json") w.Header().Set("Content-Type", "application/json")
err = json.NewEncoder(w).Encode(&specie) err = json.NewEncoder(w).Encode(&specie)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment