Skip to content

Instantly share code, notes, and snippets.

@Bebbolus
Created November 30, 2018 16:45
Show Gist options
  • Save Bebbolus/8cb6207e18be72448e10b93fc1e00c6c to your computer and use it in GitHub Desktop.
Save Bebbolus/8cb6207e18be72448e10b93fc1e00c6c to your computer and use it in GitHub Desktop.
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