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
f785ee22
Commit
f785ee22
authored
5 years ago
by
Aksel Baardsen
Browse files
Options
Downloads
Patches
Plain Diff
timeout using client on diag fix
parent
0b9066f3
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
handler/diag.go
+3
-3
3 additions, 3 deletions
handler/diag.go
pkg/diag.go
+4
-5
4 additions, 5 deletions
pkg/diag.go
pkg/funcs.go
+1
-1
1 addition, 1 deletion
pkg/funcs.go
with
8 additions
and
9 deletions
handler/diag.go
+
3
−
3
View file @
f785ee22
...
...
@@ -15,12 +15,12 @@ func Dhandler(w http.ResponseWriter, r *http.Request) {
err
:=
pkg
.
GetDiag
(
&
diagnostics
)
// if error was encountered: print error, else: return diagnostics
if
err
!=
nil
{
http
.
Error
(
w
,
err
.
Error
(),
http
.
StatusBadGateway
)
}
else
{
if
err
==
nil
{
w
.
Header
()
.
Set
(
"Content-Type"
,
"application/json"
)
if
err
:=
json
.
NewEncoder
(
w
)
.
Encode
(
&
diagnostics
);
err
!=
nil
{
log
.
Fatal
(
err
)
}
}
else
{
http
.
Error
(
w
,
err
.
Error
(),
http
.
StatusBadGateway
)
}
}
This diff is collapsed.
Click to expand it.
pkg/diag.go
+
4
−
5
View file @
f785ee22
...
...
@@ -2,7 +2,6 @@ package pkg
import
(
"fmt"
"net/http"
"time"
)
...
...
@@ -43,9 +42,9 @@ func GetDiag(d* Diag) error {
return
nil
}
// Gets GBIF-api status code
// Gets GBIF-api status code
(uses http.client defined in funcs.go)
func
getGbifStatus
(
d
*
Diag
)
error
{
resp
,
err
:=
http
.
Get
(
gbifApi
)
resp
,
err
:=
client
.
Get
(
gbifApi
)
if
err
!=
nil
{
return
err
}
...
...
@@ -53,9 +52,9 @@ func getGbifStatus(d *Diag) error {
return
nil
}
// Gets country-api status code
// Gets country-api status code
(uses http.client defined in funcs.go)
func
getRestStatus
(
d
*
Diag
)
error
{
resp
,
err
:=
http
.
Get
(
restApi
)
resp
,
err
:=
client
.
Get
(
restApi
)
if
err
!=
nil
{
return
err
}
...
...
This diff is collapsed.
Click to expand it.
pkg/funcs.go
+
1
−
1
View file @
f785ee22
...
...
@@ -10,7 +10,7 @@ import (
// creates http client for ensuring timely timeouts
var
client
=
http
.
Client
{
Timeout
:
5
*
time
.
Second
,
Timeout
:
1
5
*
time
.
Second
,
}
// allowing access to "overloaded" functions
...
...
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