MCPcopy
hub / github.com/kopia/kopia / Send

Method Send

notification/sender/pushover/pushover_sender.go:26–66  ·  view source on GitHub ↗
(ctx context.Context, msg *sender.Message)

Source from the content-addressed store, hash-verified

24}
25
26func (p *pushoverProvider) Send(ctx context.Context, msg *sender.Message) error {
27 payload := map[string]string{
28 "token": p.opt.AppToken,
29 "user": p.opt.UserKey,
30 "message": msg.Subject + "\n\n" + msg.Body,
31 }
32
33 if p.Format() == "html" {
34 payload["html"] = "1"
35 }
36
37 targetURL := defaultPushoverURL
38 if p.opt.Endpoint != "" {
39 targetURL = p.opt.Endpoint
40 }
41
42 body, err := json.Marshal(payload)
43 if err != nil {
44 return errors.Wrap(err, "error preparing pushover notification")
45 }
46
47 req, err := http.NewRequestWithContext(ctx, http.MethodPost, targetURL, bytes.NewReader(body))
48 if err != nil {
49 return errors.Wrap(err, "error preparing pushover notification")
50 }
51
52 req.Header.Set("Content-Type", "application/json")
53
54 resp, err := http.DefaultClient.Do(req)
55 if err != nil {
56 return errors.Wrap(err, "error sending pushover notification")
57 }
58
59 defer resp.Body.Close() //nolint:errcheck
60
61 if resp.StatusCode != http.StatusOK {
62 return errors.Errorf("error sending pushover notification: %v", resp.Status)
63 }
64
65 return nil
66}
67
68func (p *pushoverProvider) Summary() string {
69 return fmt.Sprintf("Pushover user %q app %q format %q", p.opt.UserKey, p.opt.AppToken, p.Format())

Callers

nothing calls this directly

Calls 3

FormatMethod · 0.95
ErrorfMethod · 0.80
CloseMethod · 0.65

Tested by

no test coverage detected