aboutsummaryrefslogtreecommitdiff
path: root/cmd/main/http.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/main/http.go')
-rw-r--r--cmd/main/http.go26
1 files changed, 17 insertions, 9 deletions
diff --git a/cmd/main/http.go b/cmd/main/http.go
index ce31495..94d6ae5 100644
--- a/cmd/main/http.go
+++ b/cmd/main/http.go
@@ -12,24 +12,28 @@ type httpCheck struct {
Code int
}
-func httpStatusWorker(jobs <-chan httpCheck, msg chan<- *string) {
+func httpStatusWorker(jobs <-chan httpCheck, msg chan<- *jobResponse) {
for hc := range jobs {
err := checkup.HttpStatusOK(hc.URL, hc.Code)
if err != nil {
- s := fmt.Sprintf("Checking: %s, %v\n",
+ s := fmt.Sprintf("Checking: %s, %v",
hc.URL, err)
- msg <- &s
+ msg <- &jobResponse{
+ Id: hc.URL + "->" + string(hc.Code),
+ Message: s,
+ Err: err,
+ }
continue
}
msg <- nil
}
}
-func checkStatus(conf *Config) {
+func checkStatus(conf *Config) map[string]*jobResponse {
buf := &bytes.Buffer{}
hc := make(chan httpCheck)
- msgs := make(chan *string)
+ msgs := make(chan *jobResponse)
for i := 1; i <= conf.Workers; i++ {
go httpStatusWorker(hc, msgs)
@@ -45,12 +49,16 @@ func checkStatus(conf *Config) {
close(hc)
}()
+ out := make(map[string]*jobResponse)
for i := 0; i < len(conf.StatusChecks); i++ {
- m := <-msgs
- if m != nil {
- buf.Write([]byte(*m))
+ resp := <-msgs
+ if resp != nil {
+ buf.Write([]byte(resp.Message))
+ out[resp.Id] = resp
}
}
- notify(conf, buf.Bytes())
+ // notify(conf, buf.Bytes())
+
+ return out
}