forked from krakend/krakend-ce
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin.go
64 lines (54 loc) · 1.55 KB
/
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
58
59
60
61
62
63
64
package krakend
import (
"github.com/luraproject/lura/v2/logging"
proxy "github.com/luraproject/lura/v2/proxy/plugin"
client "github.com/luraproject/lura/v2/transport/http/client/plugin"
server "github.com/luraproject/lura/v2/transport/http/server/plugin"
)
// LoadPlugins loads and registers the plugins so they can be used if enabled at the configuration
func LoadPlugins(folder, pattern string, logger logging.Logger) {
logger.Debug("[SERVICE: Plugin Loader] Starting loading process")
n, err := client.LoadWithLogger(
folder,
pattern,
client.RegisterClient,
logger,
)
logPluginLoaderErrors(logger, "[SERVICE: Executor Plugin]", n, err)
n, err = server.LoadWithLogger(
folder,
pattern,
server.RegisterHandler,
logger,
)
logPluginLoaderErrors(logger, "[SERVICE: Handler Plugin]", n, err)
n, err = proxy.LoadWithLogger(
folder,
pattern,
proxy.RegisterModifier,
logger,
)
logPluginLoaderErrors(logger, "[SERVICE: Modifier Plugin]", n, err)
logger.Debug("[SERVICE: Plugin Loader] Loading process completed")
}
func logPluginLoaderErrors(logger logging.Logger, tag string, n int, err error) {
if err != nil {
if mErrs, ok := err.(pluginLoaderErr); ok {
for _, err := range mErrs.Errs() {
logger.Debug(tag, err.Error())
}
} else {
logger.Debug(tag, err.Error())
}
}
if n > 0 {
logger.Info(tag, "Total plugins loaded:", n)
}
}
type pluginLoader struct{}
func (pluginLoader) Load(folder, pattern string, logger logging.Logger) {
LoadPlugins(folder, pattern, logger)
}
type pluginLoaderErr interface {
Errs() []error
}