From 1cebf3b440a35d532b51a13f4b3dd1a90e8cdab2 Mon Sep 17 00:00:00 2001 From: Mitchell Riedstra Date: Mon, 26 Jul 2021 16:58:25 -0400 Subject: hack at it a bit to support checking for things that should not redirect --- cmd/main/http.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'cmd/main/http.go') 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)) -- cgit v1.2.3