/
plugin.go
41 lines (33 loc) · 1.06 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
package plugin
import (
"context"
"net/rpc"
"github.com/hashicorp/consul/agent/connect/ca"
"github.com/hashicorp/go-plugin"
"google.golang.org/grpc"
)
// ProviderPlugin implements plugin.Plugin for initializing a plugin
// server and client for both net/rpc and gRPC.
type ProviderPlugin struct {
Impl ca.Provider
}
func (p ProviderPlugin) Server(*plugin.MuxBroker) (interface{}, error) {
return &providerPluginRPCServer{impl: p.Impl}, nil
}
func (ProviderPlugin) Client(b *plugin.MuxBroker, c *rpc.Client) (interface{}, error) {
return &providerPluginRPCClient{client: c}, nil
}
func (p ProviderPlugin) GRPCServer(_ *plugin.GRPCBroker, s *grpc.Server) error {
RegisterCAServer(s, &providerPluginGRPCServer{impl: p.Impl})
return nil
}
func (ProviderPlugin) GRPCClient(doneCtx context.Context, _ *plugin.GRPCBroker, c *grpc.ClientConn) (interface{}, error) {
return &providerPluginGRPCClient{
client: NewCAClient(c),
clientConn: c,
doneCtx: doneCtx,
}, nil
}
// Verification
var _ plugin.Plugin = ProviderPlugin{}
var _ plugin.GRPCPlugin = ProviderPlugin{}