zirconium-go/core/module_rpc_sender.go
2020-02-12 20:39:57 +04:00

49 lines
1.1 KiB
Go

package core
import (
"log"
"net/rpc"
"github.com/hashicorp/go-plugin"
)
type moduleClient struct {
Broker *plugin.MuxBroker
Client *rpc.Client
}
// Client implmentation of go-plugin.plugin.Plugin.Client
func (p *ModuleRef) Client(b *plugin.MuxBroker, c *rpc.Client) (interface{}, error) {
return &moduleClient{Broker: b, Client: c}, nil
}
// Name initiates an RPC call to the plugin name
func (p *moduleClient) Name() string {
var resp string
err := p.Client.Call("Plugin.Name", new(interface{}), &resp)
if err != nil {
log.Fatal(err) // FIXME
}
return resp
}
// Version initiates an RPC call to the plugin version
func (p *moduleClient) Version() string {
var resp string
err := p.Client.Call("Plugin.Version", new(interface{}), &resp)
if err != nil {
log.Fatal(err) // FIXME
}
return resp
}
// StartTime initiates an RPC call to the plugin for initializing
func (p *moduleClient) Initialize(moduleAPI *ModuleManager) {
err := p.Client.Call("Plugin.Initialize", map[string]interface{}{
"moduleAPI": moduleAPI,
}, nil)
if err != nil {
log.Fatal(err) // FIXME
}
}