-
Notifications
You must be signed in to change notification settings - Fork 0
/
outputer_rpc.go
58 lines (46 loc) · 1.02 KB
/
outputer_rpc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package specraft
import (
"io"
"net/rpc"
"github.com/hashicorp/go-plugin"
)
type Outputer interface {
Output(data io.Reader, opts any) error
}
type OutputerRPC struct {
client *rpc.Client
}
type OutputerOutputRequest struct {
Data io.Reader
Opts any
}
type OutputerOutputResponse struct {
Err error
}
func (o *OutputerRPC) Output(data io.Reader) error {
res := &OutputerOutputResponse{}
req := &OutputerOutputRequest{
Data: data,
}
err := o.client.Call("Plugin.Output", req, res)
if err != nil {
return err
}
return res.Err
}
type OutputerRPCServer struct {
Impl Outputer
}
func (o *OutputerRPCServer) Output(req OutputerOutputRequest, res *OutputerOutputResponse) error {
res.Err = o.Impl.Output(req.Data, req.Opts)
return nil
}
type OutputerPlugin struct {
Impl Outputer
}
func (o *OutputerPlugin) Server(*plugin.MuxBroker) (any, error) {
return &OutputerRPCServer{Impl: o.Impl}, nil
}
func (OutputerPlugin) Client(b *plugin.MuxBroker, c *rpc.Client) (any, error) {
return &OutputerRPC{client: c}, nil
}