Skip to content

Commit

Permalink
Correct error httpCheck if url get error (panic)
Browse files Browse the repository at this point in the history
Update deprecated fun
  • Loading branch information
leech001 committed Aug 21, 2022
1 parent b110845 commit 1c43807
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
app/conf/config_test.yaml
app/go.sum
app/conf/config.yaml
10 changes: 5 additions & 5 deletions app/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module main

go 1.18
go 1.19

require (
github.com/go-ping/ping v1.1.0
Expand All @@ -9,8 +9,8 @@ require (
)

require (
github.com/google/uuid v1.2.0 // indirect
golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4 // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
golang.org/x/sys v0.0.0-20210315160823-c6e025ad8005 // indirect
github.com/google/uuid v1.3.0 // indirect
golang.org/x/net v0.0.0-20220812174116-3211cb980234 // indirect
golang.org/x/sync v0.0.0-20220819030929-7fc1605a5dde // indirect
golang.org/x/sys v0.0.0-20220818161305-2296e01440c6 // indirect
)
3 changes: 3 additions & 0 deletions app/httpCheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ func httpCheck(update uint16, bot *tgbotapi.BotAPI, group int64, site struct {
if err != nil {
msg := tgbotapi.NewMessage(group, "Site "+site.Url+" HTTP get error")
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)

Expand All @@ -47,6 +49,7 @@ func httpCheck(update uint16, bot *tgbotapi.BotAPI, group int64, site struct {
msg := tgbotapi.NewMessage(group, "Site "+site.Url+" defaced. Element '"+element+"' not found.")
bot.Send(msg)
deface = true
break
}
}
if deface {
Expand Down
4 changes: 2 additions & 2 deletions app/main.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package main

import (
"io/ioutil"
"log"
"os"
"path/filepath"
"strconv"
"strings"
Expand Down Expand Up @@ -39,7 +39,7 @@ func main() {
// Read config from yaml
config := Config{}
filename, _ := filepath.Abs("./conf/config.yaml")
yamlFile, err := ioutil.ReadFile(filename)
yamlFile, err := os.ReadFile(filename)
if err != nil {
panic(err)
}
Expand Down

0 comments on commit 1c43807

Please sign in to comment.