add more functions
This commit is contained in:
parent
c3b25251f5
commit
30f21b4e7c
1 changed files with 28 additions and 2 deletions
30
ntfy.go
30
ntfy.go
|
|
@ -7,7 +7,9 @@ import (
|
|||
"net/http"
|
||||
)
|
||||
|
||||
func Send(topic, title, message string, fn func(*http.Request)) (err error) {
|
||||
type Request = http.Request
|
||||
|
||||
func SendF(topic, title, message string, fn func(*Request)) (err error) {
|
||||
req, err := http.NewRequest("POST",
|
||||
"https://ntfy.sh/" + topic, strings.NewReader(message))
|
||||
if err != nil {
|
||||
|
|
@ -30,13 +32,37 @@ func Send(topic, title, message string, fn func(*http.Request)) (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
func Send(topic, title, message string) error {
|
||||
return SendF(topic, title, message)
|
||||
}
|
||||
|
||||
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) {
|
||||
return SendF(topic, title, message, func(r *Request) {
|
||||
r.Header.Set("Actions", actionsString)
|
||||
})
|
||||
}
|
||||
|
||||
func SendPrio(topic, title, message, prio string) error {
|
||||
return SendF(topic, title, message, func(r *Request) {
|
||||
r.Header.Set("Priority", prio)
|
||||
})
|
||||
}
|
||||
|
||||
func SendTags(topic, title, message string, tags ...string) error {
|
||||
tagsString := strings.Join(tags, ",")
|
||||
return SendF(topic, title, message, func(r *Request) {
|
||||
r.Header.Set("Tags", tagsString)
|
||||
})
|
||||
}
|
||||
|
||||
func SendError(topic, title, message string) error {
|
||||
return SendF(topic, title, message, func(r *Request) {
|
||||
r.Header.Set("Priority", "urgent")
|
||||
r.Header.Set("Tags", "rotating_light,warning")
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue