refactor: extract types and pkgs to new files

This commit is contained in:
Simon Aronsson 2019-07-21 19:58:19 +02:00
parent 4a92a03f31
commit e109a7a6ce
15 changed files with 71 additions and 57 deletions

View file

@ -9,7 +9,7 @@ import (
"time"
"strconv"
t "github.com/containrrr/watchtower/pkg/types"
log "github.com/sirupsen/logrus"
)
@ -17,7 +17,7 @@ const (
emailType = "email"
)
// Implements typeNotifier, logrus.Hook
// Implements Notifier, logrus.Hook
// The default logrus email integration would have several issues:
// - It would send one email per log output
// - It would only send errors
@ -31,7 +31,7 @@ type emailTypeNotifier struct {
logLevels []log.Level
}
func newEmailNotifier(c *cobra.Command, acceptedLogLevels []log.Level) typeNotifier {
func newEmailNotifier(c *cobra.Command, acceptedLogLevels []log.Level) t.Notifier {
flags := c.PersistentFlags()
from, _ := flags.GetString("notification-email-from")

View file

@ -7,6 +7,7 @@ import (
"github.com/spf13/cobra"
"net/http"
t "github.com/containrrr/watchtower/pkg/types"
log "github.com/sirupsen/logrus"
"io/ioutil"
)
@ -21,7 +22,7 @@ type msTeamsTypeNotifier struct {
data bool
}
func newMsTeamsNotifier(cmd *cobra.Command, acceptedLogLevels []log.Level) typeNotifier {
func newMsTeamsNotifier(cmd *cobra.Command, acceptedLogLevels []log.Level) t.Notifier {
flags := cmd.PersistentFlags()

View file

@ -1,19 +1,17 @@
package notifications
import (
ty "github.com/containrrr/watchtower/pkg/types"
"github.com/johntdyer/slackrus"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
type typeNotifier interface {
StartNotification()
SendNotification()
}
// Notifier can send log output as notification to admins, with optional batching.
type Notifier struct {
types []typeNotifier
types []ty.Notifier
}
// NewNotifier creates and returns a new Notifier, using global configuration.
@ -34,7 +32,7 @@ func NewNotifier(c *cobra.Command) *Notifier {
types, _ := f.GetStringSlice("notifications")
for _, t := range types {
var tn typeNotifier
var tn ty.Notifier
switch t {
case emailType:
tn = newEmailNotifier(c, acceptedLogLevels)

View file

@ -4,6 +4,7 @@ import (
"github.com/johntdyer/slackrus"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
t "github.com/containrrr/watchtower/pkg/types"
)
const (
@ -14,7 +15,7 @@ type slackTypeNotifier struct {
slackrus.SlackrusHook
}
func newSlackNotifier(c *cobra.Command, acceptedLogLevels []log.Level) typeNotifier {
func newSlackNotifier(c *cobra.Command, acceptedLogLevels []log.Level) t.Notifier {
flags := c.PersistentFlags()
hookURL, _ := flags.GetString("notification-slack-hook-url")