| 13 | } |
| 14 | |
| 15 | func SendMessage(url string, title string, body string, transport *http.Transport) error { |
| 16 | msg := BarkMessage{ |
| 17 | Title: title, |
| 18 | Body: body, |
| 19 | } |
| 20 | data, err := json.Marshal(msg) |
| 21 | if err != nil { |
| 22 | return err |
| 23 | } |
| 24 | |
| 25 | client := &http.Client{ |
| 26 | Transport: transport, |
| 27 | } |
| 28 | |
| 29 | req, err := http.NewRequest("POST", url, bytes.NewBuffer(data)) |
| 30 | if err != nil { |
| 31 | return err |
| 32 | } |
| 33 | req.Header.Set("Content-Type", "application/json; charset=utf-8") |
| 34 | |
| 35 | resp, err := client.Do(req) |
| 36 | if err != nil { |
| 37 | return err |
| 38 | } |
| 39 | defer resp.Body.Close() |
| 40 | |
| 41 | if resp.StatusCode != http.StatusOK { |
| 42 | return fmt.Errorf("bark push failed with status code %d", resp.StatusCode) |
| 43 | } |
| 44 | |
| 45 | return nil |
| 46 | } |