mirror of
https://github.com/containrrr/watchtower.git
synced 2025-09-22 05:40:50 +02:00
reuse router
This commit is contained in:
parent
b5df48279c
commit
480f4c8ccb
1 changed files with 5 additions and 2 deletions
|
@ -3,6 +3,7 @@ package notifications
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/containrrr/shoutrrr"
|
"github.com/containrrr/shoutrrr"
|
||||||
|
"github.com/containrrr/shoutrrr/pkg/router"
|
||||||
t "github.com/containrrr/watchtower/pkg/types"
|
t "github.com/containrrr/watchtower/pkg/types"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
@ -15,6 +16,7 @@ const (
|
||||||
// Implements Notifier, logrus.Hook
|
// Implements Notifier, logrus.Hook
|
||||||
type shoutrrrTypeNotifier struct {
|
type shoutrrrTypeNotifier struct {
|
||||||
Urls []string
|
Urls []string
|
||||||
|
Router *router.ServiceRouter
|
||||||
entries []*log.Entry
|
entries []*log.Entry
|
||||||
logLevels []log.Level
|
logLevels []log.Level
|
||||||
}
|
}
|
||||||
|
@ -23,9 +25,11 @@ func newShoutrrrNotifier(c *cobra.Command, acceptedLogLevels []log.Level) t.Noti
|
||||||
flags := c.PersistentFlags()
|
flags := c.PersistentFlags()
|
||||||
|
|
||||||
urls, _ := flags.GetStringArray("notification-url")
|
urls, _ := flags.GetStringArray("notification-url")
|
||||||
|
r, _ := shoutrrr.CreateSender(urls...)
|
||||||
|
|
||||||
n := &shoutrrrTypeNotifier{
|
n := &shoutrrrTypeNotifier{
|
||||||
Urls: urls,
|
Urls: urls,
|
||||||
|
Router: r,
|
||||||
logLevels: acceptedLogLevels,
|
logLevels: acceptedLogLevels,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,8 +52,7 @@ func (e *shoutrrrTypeNotifier) sendEntries(entries []*log.Entry) {
|
||||||
// Do the sending in a separate goroutine so we don't block the main process.
|
// Do the sending in a separate goroutine so we don't block the main process.
|
||||||
msg := e.buildMessage(entries)
|
msg := e.buildMessage(entries)
|
||||||
go func() {
|
go func() {
|
||||||
router, _ := shoutrrr.CreateSender(e.Urls...)
|
errs := e.Router.Send(msg, nil)
|
||||||
errs := router.Send(msg, nil)
|
|
||||||
|
|
||||||
for i, err := range errs {
|
for i, err := range errs {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue