1
0
Fork 0
mirror of https://github.com/binwiederhier/ntfy.git synced 2024-11-23 03:43:47 +01:00
ntfy/examples/publish-go/main.go

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

28 lines
846 B
Go
Raw Normal View History

2021-12-02 05:08:12 +01:00
package main
import (
"log"
"net/http"
"strings"
)
func main() {
// Without additional headers (priority, tags, title), it's a one liner.
// Check out https://ntfy.sh/mytopic in your browser after running this.
http.Post("https://ntfy.sh/mytopic", "text/plain", strings.NewReader("Backup successful 😀"))
// If you'd like to add title, priority, or tags, it's a little harder.
// Check out https://ntfy.sh/phil_alerts in your browser.
req, err := http.NewRequest("POST", "https://ntfy.sh/phil_alerts",
strings.NewReader("Remote access to phils-laptop detected. Act right away."))
if err != nil {
log.Fatal(err)
}
req.Header.Set("Title", "Unauthorized access detected")
req.Header.Set("Priority", "urgent")
req.Header.Set("Tags", "warning,skull")
if _, err := http.DefaultClient.Do(req); err != nil {
log.Fatal(err)
}
}