From ce1f5941ab340cc903c71d3c38834de515f7caef Mon Sep 17 00:00:00 2001 From: leech001 Date: Sat, 3 Sep 2022 16:41:33 +0300 Subject: [PATCH] Bug fix (http error) --- app/httpCheck.go | 60 +++++++++++++++++++++++------------------------- 1 file changed, 29 insertions(+), 31 deletions(-) diff --git a/app/httpCheck.go b/app/httpCheck.go index 4821da3..160565f 100644 --- a/app/httpCheck.go +++ b/app/httpCheck.go @@ -28,46 +28,44 @@ func httpCheck(update uint16, bot *tgbotapi.BotAPI, group int64, site struct { elapsed := time.Since(start).Seconds() if err != nil { - msg := tgbotapi.NewMessage(group, "Site "+site.Url+" HTTP get error") - bot.Send(msg) - break - } - - if elapsed >= delay { - msg := tgbotapi.NewMessage(group, "Site "+site.Url+" HTTP delay "+strconv.FormatFloat(elapsed, 'f', 3, 32)+" sec.") - bot.Send(msg) - break - } - - bodyBytes, err := io.ReadAll(resp.Body) - if err != nil { - msg := tgbotapi.NewMessage(group, "Site "+site.Url+" HTTP get error") - bot.Send(msg) - break - } - body := string(bodyBytes) - - if resp.StatusCode != 200 { - msg := tgbotapi.NewMessage(group, "Site "+site.Url+" HTTP error. Code "+strconv.Itoa(resp.StatusCode)) - bot.Send(msg) - break - } + errorHTML++ + } else { + if resp.StatusCode != 200 { + msg := tgbotapi.NewMessage(group, "Site "+site.Url+" HTTP error. Code "+strconv.Itoa(resp.StatusCode)) + bot.Send(msg) + break + } - for _, element := range site.Elements { - if !strings.Contains(body, element) { - msg := tgbotapi.NewMessage(group, "Site "+site.Url+" defaced. Element '"+element+"' not found.") + if elapsed >= delay { + msg := tgbotapi.NewMessage(group, "Site "+site.Url+" HTTP delay "+strconv.FormatFloat(elapsed, 'f', 3, 32)+" sec.") bot.Send(msg) - deface = true break } - } - if deface { - break + + bodyBytes, err := io.ReadAll(resp.Body) + if err != nil { + errorHTML++ + } else { + body := string(bodyBytes) + + for _, element := range site.Elements { + if !strings.Contains(body, element) { + msg := tgbotapi.NewMessage(group, "Site "+site.Url+" defaced. Element '"+element+"' not found.") + bot.Send(msg) + deface = true + break + } + } + if deface { + break + } + } } } if errorHTML >= int(repeat-1) { msg := tgbotapi.NewMessage(group, "Site "+site.Url+" HTTP get error") bot.Send(msg) + errorHTML = 0 } time.Sleep(time.Duration(update) * time.Second) }