Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
Assignment1
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Andrea Magnussen
Assignment1
Commits
5795887b
Commit
5795887b
authored
5 years ago
by
andmag
Browse files
Options
Downloads
Patches
Plain Diff
species and speciesKey list
parent
5be4f0af
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
country.go
+47
-7
47 additions, 7 deletions
country.go
with
47 additions
and
7 deletions
country.go
+
47
−
7
View file @
5795887b
...
...
@@ -50,7 +50,6 @@ func HandlerCountry(w http.ResponseWriter, r *http.Request) {
}
/*
// HandlerOnlySpecies skjdfhkshfkl
func
HandlerOnlySpecies
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
...
...
@@ -58,6 +57,12 @@ func HandlerOnlySpecies(w http.ResponseWriter, r *http.Request) {
parts
:=
strings
.
Split
(
r
.
URL
.
Path
,
"/"
)
if
len
(
parts
)
!=
5
||
parts
[
1
]
!=
"conservation"
||
parts
[
2
]
!=
"v1"
||
parts
[
3
]
!=
"spec"
||
parts
[
4
]
==
""
{
status
:=
http
.
StatusBadRequest
http
.
Error
(
w
,
"Expecting format /conservation/v1/spec/'alphacode'"
,
status
)
return
}
APIURL
+=
parts
[
4
]
http
.
Header
.
Add
(
w
.
Header
(),
"content-type"
,
"application/json"
)
...
...
@@ -75,11 +80,46 @@ func HandlerOnlySpecies(w http.ResponseWriter, r *http.Request) {
defer
resp
.
Body
.
Close
()
var species []SpeciesByCountry
//species := []SpeciesByCountry{}
//mySpeciesList := make([]SBCList, 0)
json.NewDecoder(resp.Body).Decode(&species)
json.NewEncoder(w).Encode(species)
type
Result
Results
var
name
=
&
Result
{}
//v, _ := ioutil.ReadAll(resp.Body)
//fmt.Println("Body: ", string(v))
err2
:=
json
.
NewDecoder
(
resp
.
Body
)
.
Decode
(
name
)
if
err2
!=
nil
{
fmt
.
Println
(
"Error"
,
err2
.
Error
())
}
var
spec
[]
string
var
specKey
[]
int
for
k
,
v
:=
range
name
.
Res1
{
fmt
.
Println
(
k
)
fmt
.
Println
(
v
.
Species
)
spec
=
append
(
spec
,
v
.
Species
)
specKey
=
append
(
specKey
,
v
.
SpeciesKey
)
fmt
.
Println
(
v
.
SpeciesKey
)
/*for k1, v1 := range v {
fmt.Println(k1, v1)
}*/
fmt
.
Println
(
v
)
}
fmt
.
Println
(
spec
)
result
:=
Results2
{}
result
.
Res2
=
spec
result
.
Res3
=
specKey
err3
:=
json
.
NewEncoder
(
w
)
.
Encode
(
result
)
if
err3
!=
nil
{
fmt
.
Println
(
"error2"
,
err3
.
Error
())
}
}
*/
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