initial commit
This commit is contained in:
commit
a4e36cdded
2 changed files with 43 additions and 0 deletions
3
go.mod
Normal file
3
go.mod
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
module git.baxters.nz/jeremy/ntfy
|
||||
|
||||
go 1.25.7
|
||||
40
ntfy.go
Normal file
40
ntfy.go
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
package ntfy
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func Send(topic, title, message string, fn func(*http.Request)) (err error) {
|
||||
req, err := http.NewRequest("POST",
|
||||
"https://ntfy.sh/" + topic, strings.NewReader(message))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
req.Header.Set("Markdown", "true")
|
||||
fn(req)
|
||||
|
||||
resp, err := http.DefaultClient.Do(req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
|
||||
return errors.New("Host returned " + resp.Status)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func SendActions(topic, title, message string, actions ...string) error {
|
||||
var actionsString string
|
||||
for _, a := range actions {
|
||||
actionsString += "view," + a + ",clear=false;"
|
||||
}
|
||||
|
||||
return Send(topic, title, message, func(r *http.Request) {
|
||||
r.Header.Set("Actions", actionsString)
|
||||
})
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue