I'm writing a Rules Engine in Golang. My tests involve building and loading two plugins that do some very simple string comparison. I load the plugins by doing a fileglob and calling plugin.Open()
, so far so good we get two different objects back. But when I call plug.Lookup(symbol)
the symbol returned is always a reference to the first plugin.
DEBU[0000] Starting A rule
DEBU[0000] Starting A rule
I've debugged back to make sure the plugins are different objects, which they are, but the symbol lookup isn't working as expected.
Here's a contrived working example:
main.go package main
import "plugin"
import "fmt"
func main() {
aPlug, _ := plugin.Open("testdata/plugins/a.so")
aSymPlug, _ := aPlug.Lookup("Rule")
fmt.Printf("Plugin: %v loaded
", aSymPlug)
bPlug, _ := plugin.Open("testdata/plugins/b.so")
bSymPlug, _ := bPlug.Lookup("Rule")
fmt.Printf("Plugin: %v loaded
", bSymPlug)
}
a.go plugin
package main
type plugin string
func init() {
Rule = "a"
}
func (p plugin) String() string {
return string(p)
}
var Rule plugin
b.go plugin
package main
type plugin string
func init() {
Rule = "b"
}
func (p plugin) String() string {
return string(p)
}
var Rule plugin
BUT when I change the plugin to return the string "a" or "b" (doesn't matter which plugin, either or both) instead of p
then it loads the wrong plugin! i.e.
package main
type plugin string
func init() {
Rule = "b"
}
func (p plugin) String() string {
return "b"
}
var Rule plugin
This outputs:
Plugin: a loaded
Plugin: a loaded
EDIT: Added example code