aboutsummaryrefslogtreecommitdiff
path: root/cmd/main/http.go
diff options
context:
space:
mode:
authorMitchell Riedstra <mitch@riedstra.dev>2021-07-26 16:58:25 -0400
committerMitchell Riedstra <mitch@riedstra.dev>2021-07-26 16:58:25 -0400
commit1cebf3b440a35d532b51a13f4b3dd1a90e8cdab2 (patch)
treefde1b24a768c5d454ddbf544d3d6a32009689ed0 /cmd/main/http.go
parent4a4c36edde5ff9580b3ef5342d67b0117d555b61 (diff)
downloadcheckup-1cebf3b440a35d532b51a13f4b3dd1a90e8cdab2.tar.gz
checkup-1cebf3b440a35d532b51a13f4b3dd1a90e8cdab2.tar.xz
hack at it a bit to support checking for things that should not redirectHEADmaster
Diffstat (limited to 'cmd/main/http.go')
-rw-r--r--cmd/main/http.go16
1 files changed, 8 insertions, 8 deletions
diff --git a/cmd/main/http.go b/cmd/main/http.go
index 8eb4990..ef6f2a7 100644
--- a/cmd/main/http.go
+++ b/cmd/main/http.go
@@ -4,8 +4,6 @@ import (
"bytes"
"fmt"
"time"
-
- "riedstra.dev/go/checkup"
)
type httpCheck struct {
@@ -13,9 +11,11 @@ type httpCheck struct {
Code int
}
-func httpStatusWorker(jobs <-chan httpCheck, msg chan<- *jobResponse, timeout int) {
+type httpCheckFunc func(string, int, int) error
+
+func httpStatusWorker(jobs <-chan httpCheck, msg chan<- *jobResponse, timeout int, HF httpCheckFunc) {
for hc := range jobs {
- err := checkup.HttpStatusOK(hc.URL, timeout, hc.Code)
+ err := HF(hc.URL, timeout, hc.Code)
if err != nil {
s := fmt.Sprintf("Checking: %s, %v",
hc.URL, err)
@@ -31,18 +31,18 @@ func httpStatusWorker(jobs <-chan httpCheck, msg chan<- *jobResponse, timeout in
}
}
-func checkStatus(conf *Config) map[string]*jobResponse {
+func checkStatus(conf *Config, data map[string]*int, HF httpCheckFunc) map[string]*jobResponse {
buf := &bytes.Buffer{}
hc := make(chan httpCheck)
msgs := make(chan *jobResponse)
for i := 1; i <= conf.Workers; i++ {
- go httpStatusWorker(hc, msgs, conf.HTTPTimeout)
+ go httpStatusWorker(hc, msgs, conf.HTTPTimeout, HF)
}
go func() {
- for url, code := range conf.StatusChecks {
+ for url, code := range data {
if code == nil {
code = &conf.ExpectedStatusCode
}
@@ -52,7 +52,7 @@ func checkStatus(conf *Config) map[string]*jobResponse {
}()
out := make(map[string]*jobResponse)
- for i := 0; i < len(conf.StatusChecks); i++ {
+ for i := 0; i < len(data); i++ {
resp := <-msgs
if resp != nil {
buf.Write([]byte(resp.Message))