-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin.go
64 lines (56 loc) · 1.64 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 modules
import (
"errors"
"fmt"
"github.com/hellgate75/go-tcp-common/log"
"github.com/hellgate75/go-deploy/modules/meta"
"github.com/hellgate75/go-deploy/modules/proxy"
)
var Logger log.Logger = nil
var ModulesFolder = "mod"
const (
moduleAcceptanceTimeoutInSeconds int = 3
)
// Interface that describe a Request in the Deploy Manager Plugin Explorer
type SeekRequest struct {
Module string
Symbol string
}
var proxyVia proxy.Proxy = nil
func seek(module string) (meta.Converter, error) {
var errGlobal error = nil
defer func() {
if r := recover(); r != nil {
Logger.Errorf("modules.seek -> Error: %v", r)
errGlobal = errors.New(fmt.Sprintf("%v", r))
}
}()
if proxyVia == nil {
proxyVia = proxy.NewProxy()
}
var mod proxy.Module
var err error
mod, err = proxyVia.DiscoverModule(module)
Logger.Debugf("Module is present: %v", (mod != nil))
if err != nil {
return nil, err
}
var itf meta.Converter
itf, err = mod.GetComponent()
Logger.Debugf("Module (%s) Component: %v", module, itf)
if err != nil {
return nil, err
}
itf.SetLogger(Logger)
Logger.Debugf("Module (%s) Logger: %v", module, (Logger != nil))
return itf, errGlobal
}
// Load modules that matches with the command, and provide the most suitable Converter Component, or giver the reason of the error
func LoadConverterForModule(module string) (meta.Converter, error) {
converter, err := seek(module)
if err != nil {
return nil, errors.New(fmt.Sprintf("Errors fetching plugin module : \"%s\". Details: %s", module, err.Error()))
}
Logger.Debugf("modules.LoadConverterForModule -> On Module: %s, found Converters: %v", module, converter)
return converter, nil
}