Skip to content
Snippets Groups Projects
Commit f89dea67 authored by Jesper Ulsrud's avatar Jesper Ulsrud
Browse files

commit

parent 3e988171
No related branches found
No related tags found
No related merge requests found
...@@ -25,17 +25,20 @@ type dbCountry struct { ...@@ -25,17 +25,20 @@ type dbCountry struct {
func (db *dbCountry) Init() { func (db *dbCountry) Init() {
db.allCountries = make(map[string]Country) db.allCountries = make(map[string]Country)
} }
// function to return country with given id
func (db *dbCountry) ReturnCountry(codeID string) Country {
a := db.allCountries[codeID]
return a
}
// function to add to db // function to add to db
func (db *dbCountry) Add(c Country) { func (db *dbCountry) Add(c Country) {
db.allCountries[c.Code] = c db.allCountries[c.Code] = c
} }
// function to return country with given id
func (db *dbCountry) ReturnCountry(codeID string) Country {
a := db.allCountries[codeID]
return a
}
// function for returning all countries // function for returning all countries
......
...@@ -95,12 +95,11 @@ func replyWithCountry(w http.ResponseWriter, dbc countryInterface, id string, li ...@@ -95,12 +95,11 @@ func replyWithCountry(w http.ResponseWriter, dbc countryInterface, id string, li
// handler for the country endpoint // handler for the country endpoint
func handlerCountry(w http.ResponseWriter, r *http.Request) { func handlerCountry(w http.ResponseWriter, r *http.Request) {
http.Header.Set(w.Header(), "content-type", "application/json") http.Header.Add(w.Header(), "content-type", "application/json")
parts := strings.Split(r.URL.Path, "/") parts := strings.Split(r.URL.Path, "/")
addCountries(w) addCountries(w)
//var limit string = parts[5] if len(parts) > 6 || parts[5] != "" {
if len(parts) > 7 {
status := 400 status := 400
http.Error(w, http.StatusText(status), status) http.Error(w, http.StatusText(status), status)
} else { } else {
......
...@@ -10,7 +10,7 @@ import ( ...@@ -10,7 +10,7 @@ import (
func handlerSpecies(w http.ResponseWriter, r *http.Request) { func handlerSpecies(w http.ResponseWriter, r *http.Request) {
http.Header.Set(w.Header(), "content-type", "application/json") http.Header.Set(w.Header(), "content-type", "application/json")
parts := strings.Split(r.URL.Path, "/") parts := strings.Split(r.URL.Path, "/")
if len(parts) > 8 { if len(parts) > 6 || parts[5] != "" {
status := 400 status := 400
http.Error(w, http.StatusText(status), status) http.Error(w, http.StatusText(status), status)
} else { } else {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment