-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgotify.go
42 lines (33 loc) · 782 Bytes
/
gotify.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package main
import (
"encoding/json"
"errors"
"github.com/rs/zerolog/log"
)
type GotifyMessage struct {
Title string `json:"title"`
Message string `json:"message"`
}
func sendGotify(message string, title string, errCh chan ReporterError) {
// Send a message to Gotify
m := GotifyMessage{
Title: title,
Message: message,
}
e := ReporterError{
Reporter: "gotify",
}
messageJSON, err := json.Marshal(m)
if err != nil {
log.Error().Err(err).Str("reporter", "Gotify").Msg("Failed to marshal JSON")
e.Error = errors.New("failed to marshal JSON")
errCh <- e
return
}
err = sendhttpMessage("Gotify", config.Reporter.Gotify.URL+"/message?token="+config.Reporter.Gotify.Token, messageJSON)
if err != nil {
e.Error = err
errCh <- e
return
}
}