Simple blogging system written in Go https://goblog.app
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

35 lines
736 B

package main
import (
"context"
"net/http"
"strings"
"github.com/carlmjohnson/requests"
"github.com/samber/lo"
)
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
}
topic := strings.TrimPrefix(cfg.Topic, "ntfy.sh/")
server, _ := lo.Coalesce(cfg.Server, "https://ntfy.sh")
builder := requests.
URL(server + "/" + topic).
Client(a.httpClient).
UserAgent(appUserAgent).
Method(http.MethodPost).
BodyReader(strings.NewReader(msg))
if cfg.User != "" {
builder.BasicAuth(cfg.User, cfg.Pass)
}
return builder.Fetch(context.Background())
}