Commit f785ee22 authored by Aksel Baardsen's avatar Aksel Baardsen
Browse files

timeout using client on diag fix

parent 0b9066f3
......@@ -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)
}
}
......@@ -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
}
......
......@@ -10,7 +10,7 @@ import (
// creates http client for ensuring timely timeouts
var client = http.Client{
Timeout: 5 * time.Second,
Timeout: 15 * time.Second,
}
// allowing access to "overloaded" functions
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment