41 lines
631 B
Go
41 lines
631 B
Go
package module
|
|
|
|
import (
|
|
"fmt"
|
|
"plugin"
|
|
)
|
|
|
|
func Load(modulePath string) (Module, error) {
|
|
p, err := plugin.Open(modulePath)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
mod, err := p.Lookup("Module")
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return mod.(Module), nil
|
|
}
|
|
|
|
func LoadAll(modulePath string) ([]Module, error) {
|
|
var mods []Module
|
|
modules, err := List(modulePath)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
for _, modPath := range modules {
|
|
mod, err := Load(modPath)
|
|
if err != nil {
|
|
fmt.Println("could not load module " + modPath + ": " + err.Error())
|
|
continue
|
|
}
|
|
|
|
mods = append(mods, mod)
|
|
}
|
|
|
|
return mods, nil
|
|
}
|