File tree Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Original file line number Diff line number Diff line change 4
4
"fmt"
5
5
"io/ioutil"
6
6
"plugin"
7
+ "reflect"
7
8
"strings"
8
9
9
10
"github.com/ovh/configstore"
@@ -53,10 +54,15 @@ type InitializerPlugin interface {
53
54
// InitializersFromFolder loads initialization plugins compiled as .so files
54
55
// from a folder, runs them on a received pointer to a Service
55
56
func InitializersFromFolder (path string , service * Service ) error {
56
- return loadPlugins (path , func (fileName string , p plugin.Symbol ) error {
57
- plug , ok := p .(InitializerPlugin )
57
+ return loadPlugins (path , func (fileName string , pluginSymbol plugin.Symbol ) error {
58
+ reflectvalue := reflect .ValueOf (pluginSymbol )
59
+ if reflectvalue .Kind () != reflect .Ptr {
60
+ return fmt .Errorf ("failed to load Plugin from %s: received a non-pointer object" , fileName )
61
+ }
62
+ pluginInterface := reflectvalue .Elem ().Interface ()
63
+ plug , ok := pluginInterface .(InitializerPlugin )
58
64
if ! ok {
59
- return fmt .Errorf ("failed to assert type of plugin '%s': expected InitializerPlugin got %T" , fileName , p )
65
+ return fmt .Errorf ("failed to assert type of plugin '%s': expected InitializerPlugin got %T" , fileName , pluginInterface )
60
66
}
61
67
if err := plug .Init (service ); err != nil {
62
68
return fmt .Errorf ("failed to run initialization plugin: %s" , err )
You can’t perform that action at this time.
0 commit comments