I know that it is possible to look up for go-plugin symbols that were exported and type assert them into an interface. However, I wonder if is there a way to type assert them into a struct, for example. Is there a way to do it?
For example:
plugin.go
package main
type Person struct {
Name string
}
var (
P = Person{
Name: "Emma",
}
)
app.go
package main
import (
"fmt"
"plugin"
"os"
)
func main() {
plug, err := plugin.Open("./plugin.so")
if err != nil {
fmt.Println(err)
os.Exit(1)
}
sym, err := plug.Lookup("P")
if err != nil {
fmt.Println(err)
os.Exit(1)
}
var p Person
p, ok := sym.(Person)
if !ok {
fmt.Println("Wrong symbol type")
os.Exit(1)
}
fmt.Println(p.Name)
}
The symbol P, which is a Person, is found when plug.Lookup is called. However, I can't type-assert P into Person, I get an execution time error. In this example, "Wrong symbol type".
Is there a way to achieve this or the only way to share data between the plugin and the application is using interfaces?
Thanks.