Created
November 30, 2018 16:45
-
-
Save Bebbolus/8cb6207e18be72448e10b93fc1e00c6c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"os" | |
"fmt" | |
"plugin" | |
) | |
//define a local interface of what you want to get from plugin symbol | |
type MyPlug interface { | |
Talk() | |
} | |
func main() { | |
//open plugin file | |
plug, err := plugin.Open("plugins/first.so") | |
if err != nil { | |
fmt.Println(err) | |
os.Exit(-1) | |
} | |
//searc for an exported symbol | |
symbol, err := plug.Lookup("MyPlugin") | |
if err != nil { | |
fmt.Println(err) | |
os.Exit(-1) | |
} | |
// check that loaded symbol is type Controller | |
var myPlugin MyPlug | |
myPlugin, ok := symbol.(MyPlug) | |
if !ok { | |
fmt.Println("The module have wrong type") | |
os.Exit(-1) | |
} | |
//call the function | |
myPlugin.Talk() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment