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 44 "fmt"
55 "io/ioutil"
66 "plugin"
7+ "reflect"
78 "strings"
89
910 "github.com/ovh/configstore"
@@ -53,10 +54,15 @@ type InitializerPlugin interface {
5354// InitializersFromFolder loads initialization plugins compiled as .so files
5455// from a folder, runs them on a received pointer to a Service
5556func 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 )
5864 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 )
6066 }
6167 if err := plug .Init (service ); err != nil {
6268 return fmt .Errorf ("failed to run initialization plugin: %s" , err )
You can’t perform that action at this time.
0 commit comments