MCPcopy
hub / github.com/apache/devlake / LoadGoPlugins

Function LoadGoPlugins

backend/core/runner/loader.go:51–89  ·  view source on GitHub ↗
(basicRes context.BasicRes)

Source from the content-addressed store, hash-verified

49}
50
51func LoadGoPlugins(basicRes context.BasicRes) errors.Error {
52 pluginsDir := basicRes.GetConfig("PLUGIN_DIR")
53 var wg sync.WaitGroup
54 walkErr := filepath.WalkDir(pluginsDir, func(path string, d fs.DirEntry, err error) error {
55 if err != nil {
56 return err
57 }
58 fileName := d.Name()
59 if strings.HasSuffix(fileName, ".so") && fileName != ".so" {
60 pluginName := fileName[0 : len(d.Name())-3]
61 plug, loadErr := goplugin.Open(path)
62 if loadErr != nil {
63 return loadErr
64 }
65 symPluginEntry, pluginEntryError := plug.Lookup("PluginEntry")
66 if pluginEntryError != nil {
67 return pluginEntryError
68 }
69 pluginMeta, ok := symPluginEntry.(plugin.PluginMeta)
70 if !ok {
71 return errors.Default.New(fmt.Sprintf("%s PluginEntry must implement PluginMeta interface", pluginName))
72 }
73 wg.Add(1)
74 go func(pluginName string, pluginMeta plugin.PluginMeta) {
75 defer func() {
76 wg.Done()
77 }()
78 err = plugin.RegisterPlugin(pluginName, pluginMeta)
79 if err != nil {
80 panic(err)
81 }
82 basicRes.GetLogger().Info(`plugin loaded %s`, pluginName)
83 }(pluginName, pluginMeta)
84 }
85 return nil
86 })
87 wg.Wait()
88 return errors.Convert(walkErr)
89}
90
91func LoadRemotePlugins(basicRes context.BasicRes) errors.Error {
92 remotePluginDir := basicRes.GetConfig("REMOTE_PLUGIN_DIR")

Callers 1

LoadPluginsFunction · 0.85

Calls 8

WaitMethod · 0.80
GetConfigMethod · 0.65
NameMethod · 0.65
NewMethod · 0.65
InfoMethod · 0.65
GetLoggerMethod · 0.65
AddMethod · 0.45
ConvertMethod · 0.45

Tested by

no test coverage detected