Skip to content

Commit

Permalink
minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
karak1974 committed May 2, 2022
1 parent 2c958b5 commit 9ab48c3
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 27 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@

# Dependency directories (remove the comment below to include it)
# vendor/
go.mod
go.sum

config.json
28 changes: 17 additions & 11 deletions env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down
15 changes: 0 additions & 15 deletions go.mod

This file was deleted.

8 changes: 7 additions & 1 deletion handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9ab48c3

Please sign in to comment.