-
Notifications
You must be signed in to change notification settings - Fork 0
/
group.go
47 lines (37 loc) · 1022 Bytes
/
group.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
package errorg
import (
"fmt"
"plugin"
)
var symName = "Group"
// Group represents interface that will be implemented by plugins
type Group interface {
GetErrorMap() map[string]interface{}
}
// groupsInitializer adds a plugins according to given plugins
func groupsInitializer() {
for _, plg := range getConfig().Plugins {
dirname, err := getModuleFolder()
path := fmt.Sprintf("%s/%s", dirname, plg.Location)
// Open opens a Go plugin.
plug, err := plugin.Open(path)
if err != nil {
fmt.Errorf("an error occurred while opening plugin: %v", err)
return
}
//Lookup searches for a symbol named symName in plugin p.
sym, err := plug.Lookup(symName)
if err != nil {
fmt.Errorf("an error occurred while looking plugin: %v", err)
return
}
var group Group
group, ok := sym.(Group)
if !ok {
fmt.Errorf("%s", "unexpected type from module symbol")
return
}
// returned map will be added as a new key to global errors map
errorsMap[plg.Name] = group.GetErrorMap()
}
}