aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMitchell Riedstra <mitch@riedstra.dev>2021-01-24 18:29:38 -0500
committerMitchell Riedstra <mitch@riedstra.dev>2021-01-24 18:29:38 -0500
commit6ec85b96ad4fee6ec1767f6b78f92a38ce658a06 (patch)
tree520dc1c0055a44370c4aaa61fc4daaec8af16090
parent9c8cc14958c248ddba1669becb5e026d43dd997c (diff)
downloadcheckup-6ec85b96ad4fee6ec1767f6b78f92a38ce658a06.tar.gz
checkup-6ec85b96ad4fee6ec1767f6b78f92a38ce658a06.tar.xz
Allow the timeout to be adjusted
-rw-r--r--cmd/main/http.go6
-rw-r--r--cmd/main/main.go1
-rw-r--r--http.go4
3 files changed, 6 insertions, 5 deletions
diff --git a/cmd/main/http.go b/cmd/main/http.go
index 94d6ae5..fd6169e 100644
--- a/cmd/main/http.go
+++ b/cmd/main/http.go
@@ -12,9 +12,9 @@ type httpCheck struct {
Code int
}
-func httpStatusWorker(jobs <-chan httpCheck, msg chan<- *jobResponse) {
+func httpStatusWorker(jobs <-chan httpCheck, msg chan<- *jobResponse, timeout int) {
for hc := range jobs {
- err := checkup.HttpStatusOK(hc.URL, hc.Code)
+ err := checkup.HttpStatusOK(hc.URL, timeout, hc.Code)
if err != nil {
s := fmt.Sprintf("Checking: %s, %v",
hc.URL, err)
@@ -36,7 +36,7 @@ func checkStatus(conf *Config) map[string]*jobResponse {
msgs := make(chan *jobResponse)
for i := 1; i <= conf.Workers; i++ {
- go httpStatusWorker(hc, msgs)
+ go httpStatusWorker(hc, msgs, conf.HTTPTimeout)
}
go func() {
diff --git a/cmd/main/main.go b/cmd/main/main.go
index 34fc6f4..1b264a3 100644
--- a/cmd/main/main.go
+++ b/cmd/main/main.go
@@ -31,6 +31,7 @@ type Config struct {
StatusChecks map[string]*int `yaml:"StatusChecks"`
Workers int `yaml:"Workers"`
Interval int `yaml:"Interval"`
+ HTTPTimeout int `yaml:"HTTPTimeout"`
}
func ReadConfig(fn string, conf *Config) error {
diff --git a/http.go b/http.go
index 24e0b4d..daf8945 100644
--- a/http.go
+++ b/http.go
@@ -6,8 +6,8 @@ import (
"time"
)
-func HttpStatusOK(url string, status int) error {
- client := &http.Client{Timeout: 5 * time.Second}
+func HttpStatusOK(url string, timeout, status int) error {
+ client := &http.Client{Timeout: time.Duration(timeout) * time.Second}
resp, err := client.Get(url)