main.go 846 B

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