From 9ab48c3141a42876d72f3e87876135ca6efd56d8 Mon Sep 17 00:00:00 2001 From: Wolfy Date: Mon, 2 May 2022 17:21:14 +0200 Subject: [PATCH] minor changes --- .gitignore | 2 ++ env/env.go | 28 +++++++++++++++++----------- go.mod | 15 --------------- handler/handler.go | 8 +++++++- 4 files changed, 26 insertions(+), 27 deletions(-) delete mode 100644 go.mod diff --git a/.gitignore b/.gitignore index bee0cda..f0c6af6 100644 --- a/.gitignore +++ b/.gitignore @@ -13,5 +13,7 @@ # Dependency directories (remove the comment below to include it) # vendor/ +go.mod +go.sum config.json \ No newline at end of file diff --git a/env/env.go b/env/env.go index 5b70723..9cd0ed5 100644 --- a/env/env.go +++ b/env/env.go @@ -21,9 +21,14 @@ type Static struct { } type Check struct { - Type string `json:"type"` - Value string `json:"value"` - Interval string `json:"interval"` + Type string `json:"type"` + Value string `json:"value"` + Interval string `json:"interval"` + Parameters *Parameters `json:"parameters"` +} + +type Parameters struct { + StatusCode int `json:"status_code"` } func Configuration() *Static { @@ -32,17 +37,18 @@ func Configuration() *Static { if path = os.Getenv(ConfigFlag); path == "" { path = "./config.json" } - // read from path - var s Static - // json unmarshal into s - configuration = &s - + file, err := ioutil.ReadFile(path) if err != nil { - log.Printf("[ERROR] %s", err.Error()) + log.Printf("[ERROR] %s\n", err.Error()) + return nil } - - json.Unmarshal(file, &configuration) + var s Static + if err := json.Unmarshal(file, &s); err != nil { + log.Printf("[ERROR] unmarshal file: %s", err.Error()) + return nil + } + configuration = &s } return configuration diff --git a/go.mod b/go.mod deleted file mode 100644 index a9573e1..0000000 --- a/go.mod +++ /dev/null @@ -1,15 +0,0 @@ -module github.com/infiniteloopcloud/discord-downdetector - -go 1.17 - -require ( - github.com/Clinet/discordgo-embed v0.0.0-20220113222025-bafe0c917646 - github.com/bwmarrin/discordgo v0.25.0 - github.com/infiniteloopcloud/discord-jira v0.2.0 -) - -require ( - github.com/gorilla/websocket v1.4.2 // indirect - golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b // indirect - golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 // indirect -) diff --git a/handler/handler.go b/handler/handler.go index 52e99fb..df96a48 100644 --- a/handler/handler.go +++ b/handler/handler.go @@ -18,12 +18,18 @@ var channelName string // Check is the endpoint alive func Handle(body env.Check) (string, *discordgo.MessageEmbed, error) { + var statusCode = http.StatusOK code := checkHealth(body) - if code != 200 { + + if body.Parameters != nil && body.Parameters.StatusCode != 0 { + statusCode = body.Parameters.StatusCode + } + if code != statusCode { return unreachable(body, code) } else { return "", nil, nil } + } // Send an embed to the downdetector channel