go-healthchecks/cmd/utils.go

41 lines
797 B
Go
Raw Permalink Normal View History

2024-10-02 13:26:14 +00:00
package main
import (
"fmt"
"os"
gohealthchecks "git.faercol.me/faercol/go-healthchecks"
)
2024-10-02 14:11:24 +00:00
func mustParseUUIDCheck(checkID, runID string) gohealthchecks.Check {
check, err := gohealthchecks.NewUUIDCheck(checkID, runID)
2024-10-02 13:26:14 +00:00
if err != nil {
failf("Invalid UUID: %s\n", err)
}
return check
}
func parseCheckFlags() gohealthchecks.Check {
var check gohealthchecks.Check
2024-10-02 14:11:24 +00:00
var err error
2024-10-02 13:26:14 +00:00
if checkUUID != "" {
2024-10-02 14:11:24 +00:00
check = mustParseUUIDCheck(checkUUID, runID)
2024-10-02 13:26:14 +00:00
} else {
2024-10-02 14:11:24 +00:00
check, err = gohealthchecks.NewSlugCheck(pingKey, checkSlug, autoCreate, runID)
if err != nil {
failf("Invalid UUID: %s\n", err)
}
2024-10-02 13:26:14 +00:00
}
return check
}
func failf(format string, args ...any) {
fmt.Fprintf(os.Stderr, format, args...)
os.Exit(1)
}
func failln(msg string) {
fmt.Fprintln(os.Stderr, msg)
os.Exit(1)
}