mirror of
https://github.com/crazy-max/diun.git
synced 2025-12-21 21:33:22 +01:00
Review user-agent string for some notifications
This commit is contained in:
@@ -42,8 +42,11 @@ func New(cfg *config.Config, location *time.Location) (*Diun, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// User-Agent
|
||||
userAgent := fmt.Sprintf("diun/%s go/%s %s", cfg.App.Version, runtime.Version()[2:], strings.Title(runtime.GOOS))
|
||||
|
||||
// Notification client
|
||||
notifcli, err := notif.New(cfg.Notif, cfg.App)
|
||||
notifcli, err := notif.New(cfg.Notif, cfg.App, userAgent)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -55,7 +58,7 @@ func New(cfg *config.Config, location *time.Location) (*Diun, error) {
|
||||
)),
|
||||
db: dbcli,
|
||||
notif: notifcli,
|
||||
userAgent: fmt.Sprintf("diun/%s go/%s %s", cfg.App.Version, runtime.Version()[2:], strings.Title(runtime.GOOS)),
|
||||
userAgent: userAgent,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ type Client struct {
|
||||
}
|
||||
|
||||
// New creates a new notification instance
|
||||
func New(config model.Notif, app model.App) (*Client, error) {
|
||||
func New(config model.Notif, app model.App, userAgent string) (*Client, error) {
|
||||
var c = &Client{
|
||||
cfg: config,
|
||||
app: app,
|
||||
@@ -37,10 +37,10 @@ func New(config model.Notif, app model.App) (*Client, error) {
|
||||
c.notifiers = append(c.notifiers, telegram.New(config.Telegram, app))
|
||||
}
|
||||
if config.Webhook.Enable {
|
||||
c.notifiers = append(c.notifiers, webhook.New(config.Webhook, app))
|
||||
c.notifiers = append(c.notifiers, webhook.New(config.Webhook, app, userAgent))
|
||||
}
|
||||
if config.Gotify.Enable {
|
||||
c.notifiers = append(c.notifiers, gotify.New(config.Gotify, app))
|
||||
c.notifiers = append(c.notifiers, gotify.New(config.Gotify, app, userAgent))
|
||||
}
|
||||
|
||||
log.Debug().Msgf("%d notifier(s) created", len(c.notifiers))
|
||||
|
||||
@@ -21,14 +21,16 @@ type Client struct {
|
||||
*notifier.Notifier
|
||||
cfg model.NotifGotify
|
||||
app model.App
|
||||
userAgent string
|
||||
}
|
||||
|
||||
// New creates a new gotify notification instance
|
||||
func New(config model.NotifGotify, app model.App) notifier.Notifier {
|
||||
func New(config model.NotifGotify, app model.App, userAgent string) notifier.Notifier {
|
||||
return notifier.Notifier{
|
||||
Handler: &Client{
|
||||
cfg: config,
|
||||
app: app,
|
||||
userAgent: userAgent,
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -77,7 +79,7 @@ func (c *Client) Send(entry model.NotifEntry) error {
|
||||
|
||||
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
||||
req.Header.Add("Content-Length", strconv.Itoa(len(data.Encode())))
|
||||
req.Header.Set("User-Agent", fmt.Sprintf("%s %s", c.app.Name, c.app.Version))
|
||||
req.Header.Set("User-Agent", c.userAgent)
|
||||
|
||||
resp, err := hc.Do(req)
|
||||
if err != nil {
|
||||
|
||||
@@ -3,7 +3,6 @@ package webhook
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
@@ -17,14 +16,16 @@ type Client struct {
|
||||
*notifier.Notifier
|
||||
cfg model.NotifWebhook
|
||||
app model.App
|
||||
userAgent string
|
||||
}
|
||||
|
||||
// New creates a new webhook notification instance
|
||||
func New(config model.NotifWebhook, app model.App) notifier.Notifier {
|
||||
func New(config model.NotifWebhook, app model.App, userAgent string) notifier.Notifier {
|
||||
return notifier.Notifier{
|
||||
Handler: &Client{
|
||||
cfg: config,
|
||||
app: app,
|
||||
userAgent: userAgent,
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -76,7 +77,7 @@ func (c *Client) Send(entry model.NotifEntry) error {
|
||||
}
|
||||
}
|
||||
|
||||
req.Header.Set("User-Agent", fmt.Sprintf("%s %s", c.app.Name, c.app.Version))
|
||||
req.Header.Set("User-Agent", c.userAgent)
|
||||
|
||||
_, err = hc.Do(req)
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user