hashicorp / go-plugin

Golang plugin system over RPC.
Mozilla Public License 2.0
5.25k stars 450 forks source link

arguments include context or function is supported ? #190

Open sunblack110 opened 2 years ago

sunblack110 commented 2 years ago

Hi,

I was the first time to use the go-plugin library for my project . I met a question that confuse me . I have a function like :

type Trigger interface { Listen(ctx context.Context, callback func()) error }

When I pass the callbacck function as an argument, it was receive null in the Server side .

func (g *TriggerRPC) Listen(ctx context.Context, callback func()) error { var resp string if callback == nil { log.Println("client callback is nil") } else { log.Println("client callback is not nil") } return g.client.Call("Plugin.Listen", &TriggerParam{ Context: ctx, Callback: callback, }, &resp) }

func (s TriggerRPCServer) Listen(args TriggerParam, resp *string) error { if args.Callback != nil { log.Println("Callback is not null") } else { log.Println("Callback is null") } return s.Impl.Listen(args.Context, args.Callback) }

log as flowing:

2022-03-30T16:59:49.293+0800 [DEBUG] plugin: starting plugin: path=./plugins/core-plugin.exe args=["./plugins/core-plugin.exe"] 2022-03-30T16:59:49.295+0800 [DEBUG] plugin: plugin started: path=./plugins/core-plugin.exe pid=25375 2022-03-30T16:59:49.295+0800 [DEBUG] plugin: waiting for RPC address: path=./plugins/core-plugin.exe 2022-03-30T16:59:49.622+0800 [DEBUG] plugin: using plugin: version=1 2022-03-30T16:59:49.622+0800 [DEBUG] plugin.core-plugin.exe: plugin address: address=/var/folders/31/7yy3gxrj1xz2rrd7dgv7n97w0000gn/T/plugin1868677073 network=unix timestamp="2022-03-30T16:59:49.622+0800" 2022/03/30 16:59:49 client callback is not nil 2022-03-30T16:59:49.623+0800 [DEBUG] plugin.core-plugin.exe: 2022/03/30 16:59:49 Callback is null 2022-03-30T16:59:49.623+0800 [ERROR] plugin.core-plugin.exe: Trigger Listen: timestamp="2022-03-30T16:59:49.623+0800" 2022/03/30 16:59:49 =================> create new plugin id: bd044dc6-a674-472d-8dc4-ad3d87a791f3 2022-03-30T16:59:49.624+0800 [DEBUG] plugin.core-plugin.exe: 2022/03/30 16:59:49 get impl id: bd044dc6-a674-472d-8dc4-ad3d87a791f3

but when I check the readme file .

Bidirectional communication. Because the plugin system supports complex arguments, the host process can send it interface implementations and the plugin can call back into the host process.

Did I do something wrong?

And I also have some question about the context. It will be submited on another issue.

Thanks in advance.