-
Notifications
You must be signed in to change notification settings - Fork 0
/
pluginloading.go
48 lines (41 loc) · 1.28 KB
/
pluginloading.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
package main
import (
"net/http"
"strings"
"go.uber.org/zap"
"github.com/CyrilPeponnet/slackhal/plugin"
)
func initPlugins(disabledPlugins []string, httpPort string, output chan<- *plugin.SlackResponse, bot *plugin.Bot) {
// Loading our plugin and Init them
handlers := false
if len(disabledPlugins) != 0 {
zap.L().Info("Plugins disabled", zap.String("plugins", strings.Join(disabledPlugins, ", ")))
}
zap.L().Info("Loading plugins")
Loading:
for _, p := range plugin.PluginManager.Plugins {
meta := p.GetMetadata()
for _, disabled := range disabledPlugins {
if meta.Name == disabled {
meta.Disabled = true
continue Loading
}
}
zap.L().Info("Loading", zap.String("plugin", meta.Name), zap.String("version", meta.Version))
p.Init(output, bot)
// Register handlers if any
for route, handler := range meta.HTTPHandler {
handlers = true
zap.L().Info("Registering HTTP handler", zap.String("plugin", route.Name), zap.String("address", httpPort))
http.Handle(route.Name, handler)
}
}
// Start the http handler if we have some handlers registered.
if handlers {
go func() {
if err := http.ListenAndServe(httpPort, nil); err != nil {
zap.L().Fatal("Failed to register HTTP handler", zap.String("address", httpPort), zap.Error(err))
}
}()
}
}