Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
Assignment 1
Manage
Activity
Members
Plan
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Repository analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Aksel Baardsen
Assignment 1
Commits
afe1a985
Commit
afe1a985
authored
5 years ago
by
Aksel Baardsen
Browse files
Options
Downloads
Patches
Plain Diff
changed from [] to map
parent
69cf765f
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
main.go
+1
-5
1 addition, 5 deletions
main.go
pkg/country.go
+10
-1
10 additions, 1 deletion
pkg/country.go
with
11 additions
and
6 deletions
main.go
+
1
−
5
View file @
afe1a985
...
...
@@ -5,14 +5,11 @@ import (
"github.com/gorilla/mux"
"log"
"net/http"
"os"
)
func
main
()
{
r
:=
mux
.
NewRouter
()
port
:=
os
.
Getenv
(
"PORT"
)
port
:=
"5000"
//
os.Getenv("PORT")
c
:=
r
.
PathPrefix
(
"/conservation/v1"
)
.
Methods
(
"GET"
)
.
Subrouter
()
// two handlerpaths makes sure that the caller does not HAVE to specify limit
...
...
@@ -31,6 +28,5 @@ func main() {
http
.
Handle
(
"/"
,
r
)
log
.
Fatal
(
http
.
ListenAndServe
(
":"
+
port
,
nil
))
}
This diff is collapsed.
Click to expand it.
pkg/country.go
+
10
−
1
View file @
afe1a985
...
...
@@ -54,8 +54,15 @@ func GetCountryByCode(code, limit string) (Country, int) {
}
// adds species-keys & specie-names to the country struct
check
:=
make
(
map
[
Results
]
bool
)
for
i
,
_
:=
range
species
.
Results
{
// and checks if the country-code is correct
if
check
[
species
.
Results
[
i
]]
{
continue
}
check
[
species
.
Results
[
i
]]
=
true
country
.
SpeciesKey
=
append
(
country
.
SpeciesKey
,
species
.
Results
[
i
]
.
SpeciesKey
)
country
.
Species
=
append
(
country
.
Species
,
species
.
Results
[
i
]
.
Species
)
/* and checks if the country-code is correct
if country.Code == species.Results[i].CountryCode {
// and checks that the species is unique
if species.Results[i].SpeciesKey > 0 && !contains(country.SpeciesKey, species.Results[i].SpeciesKey) {
...
...
@@ -63,6 +70,8 @@ func GetCountryByCode(code, limit string) (Country, int) {
country.SpeciesKey = append(country.SpeciesKey, species.Results[i].SpeciesKey)
}
}
*/
}
return
country
,
status
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment