| 1 |
package main |
| 2 |
|
| 3 |
import ( |
| 4 |
"log" |
| 5 |
"net/http" |
| 6 |
"strings" |
| 7 |
) |
| 8 |
|
| 9 |
func main() { |
| 10 |
// Without additional headers (priority, tags, title), it's a one liner. |
| 11 |
// Check out https://ntfy.sh/mytopic in your browser after running this. |
| 12 |
http.Post("https://ntfy.sh/mytopic", "text/plain", strings.NewReader("Backup successful 😀")) |
| 13 |
|
| 14 |
// If you'd like to add title, priority, or tags, it's a little harder. |
| 15 |
// Check out https://ntfy.sh/phil_alerts in your browser. |
| 16 |
req, err := http.NewRequest("POST", "https://ntfy.sh/phil_alerts", |
| 17 |
strings.NewReader("Remote access to phils-laptop detected. Act right away.")) |
| 18 |
if err != nil { |
| 19 |
log.Fatal(err) |
| 20 |
} |
| 21 |
req.Header.Set("Title", "Unauthorized access detected") |
| 22 |
req.Header.Set("Priority", "urgent") |
| 23 |
req.Header.Set("Tags", "warning,skull") |
| 24 |
if _, err := http.DefaultClient.Do(req); err != nil { |
| 25 |
log.Fatal(err) |
| 26 |
} |
| 27 |
} |