Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Aksel Baardsen
Assignment 1
Commits
1e5bd626
Commit
1e5bd626
authored
Oct 19, 2019
by
Aksel Baardsen
Browse files
added comments for all handlers
parent
2817db40
Changes
3
Hide whitespace changes
Inline
Side-by-side
handler/country.go
View file @
1e5bd626
...
...
@@ -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
{
...
...
handler/diag.go
View file @
1e5bd626
...
...
@@ -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
{
...
...
handler/species.go
View file @
1e5bd626
...
...
@@ -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
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment