-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathplugin.go
61 lines (49 loc) · 1.54 KB
/
plugin.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
59
60
61
package benchmark
import (
"github.com/hashicorp/go-plugin"
"net/rpc"
)
// RandIntResponder is a responder for hashicorp/go-plugin
type RandIntResponder interface {
Respond() int
}
// RandIntRPC is a struct used for hashicorp/go-plugin
type RandIntRPC struct{ client *rpc.Client }
// Respond is a function used while benchmarking hashicorp/go-plugin
func (g *RandIntRPC) Respond() int {
var resp int
err := g.client.Call("Plugin.Respond", new(interface{}), &resp)
if err != nil {
panic(err)
}
return resp
}
// RandIntRPCServer is the RPC server used when benchmarking hashicorp/go-plugin
type RandIntRPCServer struct {
Impl RandIntResponder
}
// Respond is a function used while benchmarking hashicorp/go-plugin
func (s *RandIntRPCServer) Respond(args interface{}, resp *int) error {
*resp = s.Impl.Respond()
return nil
}
// RandIntPlugin is a struct used while benchmarking hashicorp/go-plugin
type RandIntPlugin struct {
Impl RandIntResponder
}
// Server is the server used while benchmarking hashicorp/go-plugin
func (p *RandIntPlugin) Server(*plugin.MuxBroker) (interface{}, error) {
return &RandIntRPCServer{Impl: p.Impl}, nil
}
// Client is the client used while benchmarking hashicorp/go-plugin
func (RandIntPlugin) Client(b *plugin.MuxBroker, c *rpc.Client) (interface{}, error) {
return &RandIntRPC{client: c}, nil
}
type plug struct {
client *rpc.Client
}
// RandInt is a function used for testing natefinch/pie
func (p plug) RandInt(in int) (result int, err error) {
err = p.client.Call("Plugin.RandInt", in, &result)
return result, err
}