mirror of
https://github.com/nikoksr/notify.git
synced 2024-11-28 08:39:13 +02:00
Removed pseudo
This commit is contained in:
parent
f14ac841f6
commit
472ffde83c
@ -25,13 +25,9 @@ type Notifier interface {
|
||||
// service under the hood.
|
||||
func New() *Notify {
|
||||
notifier := &Notify{
|
||||
Disabled: defaultDisabled,
|
||||
Disabled: defaultDisabled,
|
||||
notifiers: []Notifier{},
|
||||
}
|
||||
|
||||
// Use the pseudo Notifier to prevent from nil reference bugs when using the Notify Notifier. In case no notifiers
|
||||
// are provided or the creation of all other notifiers failed, the pseudo Notifier will be used under the hood
|
||||
// doing nothing but preventing nil-reference errors.
|
||||
notifier.usePseudo()
|
||||
|
||||
return notifier
|
||||
}
|
||||
|
@ -1,15 +0,0 @@
|
||||
package pseudo
|
||||
|
||||
// Pseudo struct represents a dummy notification service.
|
||||
type Pseudo struct{}
|
||||
|
||||
// New returns a new instance of a Pseudo notification service. This is used internally to initialize
|
||||
// notification services list and prevent nil-reference errors.
|
||||
func New() *Pseudo {
|
||||
return &Pseudo{}
|
||||
}
|
||||
|
||||
// Send basically does nothing. Just here to conform the notify.Notifier interface.
|
||||
func (Pseudo) Send(string, string) error {
|
||||
return nil
|
||||
}
|
17
use.go
17
use.go
@ -1,9 +1,5 @@
|
||||
package notify
|
||||
|
||||
import (
|
||||
"github.com/nikoksr/notify/service/pseudo"
|
||||
)
|
||||
|
||||
// useService adds a given service to the notifiers services list. If the list still contains
|
||||
// a pseudo service we remove it before adding the 'real' service.
|
||||
func (n *Notify) useService(service Notifier) {
|
||||
@ -11,22 +7,9 @@ func (n *Notify) useService(service Notifier) {
|
||||
return
|
||||
}
|
||||
|
||||
// Remove pseudo service in case a 'real' service will be added
|
||||
if len(n.notifiers) > 0 {
|
||||
_, isPseudo := n.notifiers[0].(*pseudo.Pseudo)
|
||||
if isPseudo {
|
||||
n.notifiers = n.notifiers[1:]
|
||||
}
|
||||
}
|
||||
|
||||
n.notifiers = append(n.notifiers, service)
|
||||
}
|
||||
|
||||
// usePseudo adds a pseudo notification service to the notifiers services list.
|
||||
func (n *Notify) usePseudo() {
|
||||
n.useService(pseudo.New())
|
||||
}
|
||||
|
||||
// UseService adds a given service to the notifiers services list.
|
||||
func (n *Notify) UseService(service Notifier) {
|
||||
n.useService(service)
|
||||
|
Loading…
Reference in New Issue
Block a user