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
08495e59
Commit
08495e59
authored
Oct 3, 2019
by
Aksel Baardsen
Browse files
Options
Downloads
Patches
Plain Diff
/country works, but yes no
parent
75349573
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
models/countries.go
+48
-12
48 additions, 12 deletions
models/countries.go
with
48 additions
and
12 deletions
models/countries.go
+
48
−
12
View file @
08495e59
...
...
@@ -8,23 +8,32 @@ import (
)
const
countryApi
=
"https://restcountries.eu/rest/v2/alpha/"
const
occurrenceApi
=
"http://api.gbif.org/v1/occurrence/search?"
type
Country
struct
{
Code
string
`json:"alpha2Code"`
CountryName
string
`json:"name"`
CountryFlag
string
`json:"flag"`
Species
[]
Specie
`json:"species"`
SpeciesKey
[]
int
`json:"specieskey"`
Species
[]
string
`json:"species"`
SpeciesKey
[]
int
`json:"speciesKey"`
}
type
Response
struct
{
Results
[]
Results
`json:"results"`
}
type
Results
struct
{
Species
string
`json:"species"`
SpeciesKey
int
`json:"speciesKey"`
}
func
GetCountryByCode
(
code
,
limit
string
)
Country
{
var
x
Country
url
:=
countryApi
+
code
if
len
(
limit
)
>
0
{
url
+=
"?limit="
+
limit
}
resp
,
err
:=
http
.
Get
(
url
)
if
err
!=
nil
{
...
...
@@ -46,14 +55,41 @@ func GetCountryByCode(code, limit string) Country {
}
// #########################################################################################
var
y
Response
url2
:=
occurrenceApi
+
"countryCode="
+
code
if
len
(
limit
)
>
0
{
url2
+=
"&limit="
+
limit
}
else
{
url2
+=
"&limit=5"
}
resp2
,
err
:=
http
.
Get
(
url2
)
if
err
!=
nil
{
log
.
Fatal
(
err
)
}
defer
resp2
.
Body
.
Close
()
if
resp2
.
StatusCode
==
http
.
StatusOK
{
bodyBytes
,
err
:=
ioutil
.
ReadAll
(
resp2
.
Body
)
if
err
!=
nil
{
log
.
Fatal
(
err
)
}
/*
country := &Country{}
err = json.NewDecoder(resp.Body).Decode(country)
bodyString
:=
string
(
bodyBytes
)
err
=
json
.
Unmarshal
([]
byte
(
bodyString
),
&
y
)
if
err
!=
nil
{
log
.
Fatal
(
err
)
}*/
}
//log.Info(bodyString)
}
//adds specieskeys&specienames to the country struct
for
i
:=
0
;
i
<
len
(
y
.
Results
);
i
++
{
x
.
Species
=
append
(
x
.
Species
,
y
.
Results
[
i
]
.
Species
)
x
.
SpeciesKey
=
append
(
x
.
SpeciesKey
,
y
.
Results
[
i
]
.
SpeciesKey
)
}
return
x
...
...
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