diff options
| author | Mitchell Riedstra <mitch@riedstra.dev> | 2021-07-26 16:58:25 -0400 |
|---|---|---|
| committer | Mitchell Riedstra <mitch@riedstra.dev> | 2021-07-26 16:58:25 -0400 |
| commit | 1cebf3b440a35d532b51a13f4b3dd1a90e8cdab2 (patch) | |
| tree | fde1b24a768c5d454ddbf544d3d6a32009689ed0 /cmd/main/http.go | |
| parent | 4a4c36edde5ff9580b3ef5342d67b0117d555b61 (diff) | |
| download | checkup-master.tar.gz checkup-master.tar.xz | |
Diffstat (limited to 'cmd/main/http.go')
| -rw-r--r-- | cmd/main/http.go | 16 |
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)) |
