2021-12-29 06:09:42 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2022-01-04 08:48:37 +00:00
|
|
|
"net/http"
|
2021-12-29 06:09:42 +00:00
|
|
|
"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).
|
2021-12-29 06:09:42 +00:00
|
|
|
BodyReader(strings.NewReader(msg)).
|
|
|
|
Fetch(context.Background())
|
|
|
|
}
|