statping/types/services/notifier.go

38 lines
1.1 KiB
Go
Raw Normal View History

2020-03-14 03:13:20 +00:00
package services
import (
"github.com/statping/statping/types/failures"
"github.com/statping/statping/types/notifications"
)
var (
allNotifiers = make(map[string]ServiceNotifier)
2020-03-14 03:13:20 +00:00
)
func AllNotifiers() map[string]ServiceNotifier {
2020-03-14 03:13:20 +00:00
return allNotifiers
}
func ReturnNotifier(method string) ServiceNotifier {
return allNotifiers[method]
}
2020-03-25 18:46:50 +00:00
func FindNotifier(method string) *notifications.Notification {
n := allNotifiers[method]
if n != nil {
notif := n.Select()
no, _ := notifications.Find(notif.Method)
return notif.UpdateFields(no)
2020-03-25 18:46:50 +00:00
}
return nil
}
2020-03-14 03:13:20 +00:00
type ServiceNotifier interface {
OnSuccess(Service) (string, error) // OnSuccess is triggered when a service is successful
OnFailure(Service, failures.Failure) (string, error) // OnFailure is triggered when a service is failing
OnTest() (string, error) // OnTest is triggered for testing
OnSave() (string, error) // OnSave is triggered for testing
Select() *notifications.Notification // OnTest is triggered for testing
Valid(notifications.Values) error // Valid checks your form values
2020-03-14 03:13:20 +00:00
}