-
Notifications
You must be signed in to change notification settings - Fork 911
/
plugin.go
57 lines (47 loc) · 926 Bytes
/
plugin.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package feeds
import (
"github.com/jonas747/yagpdb/common"
"github.com/sirupsen/logrus"
"strings"
"sync"
)
type Plugin interface {
common.Plugin
StartFeed()
StopFeed(*sync.WaitGroup)
}
var (
runningPlugins = make([]Plugin, 0)
)
// Run runs the specified feeds
func Run(which []string) {
for _, plugin := range common.Plugins {
fp, ok := plugin.(Plugin)
if !ok {
continue
}
if len(which) > 0 {
found := false
for _, feed := range which {
if strings.EqualFold(feed, plugin.Name()) {
found = true
break
}
}
if !found {
logrus.Info("Ignoring feed", plugin.Name())
continue
}
}
logrus.Info("Starting feed ", plugin.Name())
go fp.StartFeed()
runningPlugins = append(runningPlugins, fp)
}
}
func Stop(wg *sync.WaitGroup) {
for _, plugin := range runningPlugins {
logrus.Info("Stopping feed ", plugin.Name())
wg.Add(1)
go plugin.StopFeed(wg)
}
}