-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtransformer_interface.go
56 lines (45 loc) · 1.46 KB
/
transformer_interface.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
package plugins
import (
"net/rpc"
"github.com/damianoneill/h7t/pkg/dsl"
"github.com/hashicorp/go-plugin"
)
// Arguments - composite for passing data across net/rpc
type Arguments struct {
InputDirectory string
CmdLineArgs []string
}
// Transformer is the interface that must be implemented by plugin authors.
type Transformer interface {
Devices(args Arguments) (dsl.Devices, error)
}
// TransformerRPC - an implementation that talks over RPC
type TransformerRPC struct{ client *rpc.Client }
// Devices - interface implementation
func (g *TransformerRPC) Devices(args Arguments) (resp dsl.Devices, err error) {
err = g.client.Call("Plugin.Devices", args, &resp)
return
}
// TransformerRPCServer - is the RPC server that TransformerRPC talks to, conforming to
// the requirements of net/rpc
type TransformerRPCServer struct {
Impl Transformer
}
// Devices - Server implementation
func (s *TransformerRPCServer) Devices(args Arguments, resp *dsl.Devices) (err error) {
*resp, err = s.Impl.Devices(args)
return
}
// TransformerPlugin is the implementation of plugin.Devices so we can serve/consume this
type TransformerPlugin struct {
// Impl Injection
Impl Transformer
}
// Server - muxing
func (p *TransformerPlugin) Server(*plugin.MuxBroker) (interface{}, error) {
return &TransformerRPCServer{Impl: p.Impl}, nil
}
// Client - muxing
func (TransformerPlugin) Client(b *plugin.MuxBroker, c *rpc.Client) (interface{}, error) {
return &TransformerRPC{client: c}, nil
}