GoBlog/ntfy.go

30 lines
511 B
Go
Raw Normal View History

package main
import (
"context"
2022-01-04 08:48:37 +00:00
"net/http"
"strings"
"github.com/carlmjohnson/requests"
)
func (ntfy *configNtfy) enabled() bool {
if ntfy == nil || !ntfy.Enabled || ntfy.Topic == "" {
return false
}
return true
}
func (a *goBlog) sendNtfy(cfg *configNtfy, msg string) error {
if !cfg.enabled() {
return nil
}
return requests.
URL(cfg.Topic).
Client(a.httpClient).
UserAgent(appUserAgent).
2022-01-04 08:48:37 +00:00
Method(http.MethodPost).
BodyReader(strings.NewReader(msg)).
Fetch(context.Background())
}