statping/core/events.go

83 lines
1.9 KiB
Go
Raw Normal View History

2018-08-16 06:22:20 +00:00
// Statup
// Copyright (C) 2018. Hunter Long and the project contributors
// Written by Hunter Long <info@socialeck.com> and the project contributors
//
// https://github.com/hunterlong/statup
//
// The licenses for most software and other practical works are designed
// to take away your freedom to share and change the works. By contrast,
// the GNU General Public License is intended to guarantee your freedom to
// share and change all versions of a program--to make sure it remains free
// software for all its users.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
2018-06-30 00:57:05 +00:00
package core
2018-06-14 01:19:00 +00:00
2018-06-19 04:48:25 +00:00
import (
"github.com/fatih/structs"
"github.com/hunterlong/statup/notifiers"
2018-07-14 02:37:39 +00:00
"github.com/hunterlong/statup/types"
"github.com/jinzhu/gorm"
2018-06-19 04:48:25 +00:00
)
func OnLoad(db *gorm.DB) {
2018-07-03 21:39:56 +00:00
for _, p := range CoreApp.AllPlugins {
p.OnLoad(*db)
2018-06-19 04:48:25 +00:00
}
}
2018-06-14 01:19:00 +00:00
2018-08-19 00:37:00 +00:00
func OnSuccess(s *Service) {
2018-07-03 21:39:56 +00:00
for _, p := range CoreApp.AllPlugins {
2018-06-19 04:48:25 +00:00
p.OnSuccess(structs.Map(s))
2018-06-14 01:19:00 +00:00
}
notifiers.OnSuccess(s.Service)
2018-06-14 01:19:00 +00:00
}
func OnFailure(s *Service, f *types.Failure) {
2018-07-03 21:39:56 +00:00
for _, p := range CoreApp.AllPlugins {
2018-06-19 04:48:25 +00:00
p.OnFailure(structs.Map(s))
}
notifiers.OnFailure(s.Service)
2018-06-19 04:48:25 +00:00
}
2018-07-17 09:18:20 +00:00
func OnSettingsSaved(c *types.Core) {
2018-07-03 21:39:56 +00:00
for _, p := range CoreApp.AllPlugins {
2018-06-19 04:48:25 +00:00
p.OnSettingsSaved(structs.Map(c))
}
}
func OnNewUser(u *User) {
2018-07-03 21:39:56 +00:00
for _, p := range CoreApp.AllPlugins {
2018-06-19 04:48:25 +00:00
p.OnNewUser(structs.Map(u))
}
}
2018-08-19 00:37:00 +00:00
func OnNewService(s *Service) {
2018-07-03 21:39:56 +00:00
for _, p := range CoreApp.AllPlugins {
2018-06-19 04:48:25 +00:00
p.OnNewService(structs.Map(s))
}
}
2018-08-19 00:37:00 +00:00
func OnDeletedService(s *Service) {
2018-07-03 21:39:56 +00:00
for _, p := range CoreApp.AllPlugins {
2018-06-19 04:48:25 +00:00
p.OnDeletedService(structs.Map(s))
}
}
2018-08-19 00:37:00 +00:00
func OnUpdateService(s *Service) {
2018-07-03 21:39:56 +00:00
for _, p := range CoreApp.AllPlugins {
2018-06-19 04:48:25 +00:00
p.OnUpdatedService(structs.Map(s))
2018-06-14 01:19:00 +00:00
}
}
2018-07-17 09:18:20 +00:00
func SelectPlugin(name string) types.PluginActions {
2018-07-03 21:39:56 +00:00
for _, p := range CoreApp.AllPlugins {
2018-06-14 01:19:00 +00:00
if p.GetInfo().Name == name {
return p
}
}
2018-07-17 09:18:20 +00:00
return types.PluginInfo{}
2018-06-14 01:19:00 +00:00
}