-
Notifications
You must be signed in to change notification settings - Fork 519
/
plugin_interface.go
35 lines (29 loc) · 1.12 KB
/
plugin_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
package plugin
import (
"context"
"github.com/hashicorp/go-plugin"
"github.com/opencost/opencost/core/pkg/model/pb"
grpc "google.golang.org/grpc"
)
// plugin interface
type CustomCostSource interface {
GetCustomCosts(req *pb.CustomCostRequest) []*pb.CustomCostResponse
}
type CustomCostPlugin struct {
plugin.Plugin
// Impl Injection
Impl CustomCostSource
}
// this method is called for as part of the reference plugin implementation
// see https://github.com/hashicorp/go-plugin/blob/main/examples/basic/shared/greeter_interface.go#L59
// for context and details
func (p *CustomCostPlugin) GRPCServer(broker *plugin.GRPCBroker, s *grpc.Server) error {
pb.RegisterCustomCostsSourceServer(s, &GRPCServer{Impl: p.Impl})
return nil
}
// this method is called for as part of the reference plugin implementation
// see https://github.com/hashicorp/go-plugin/blob/main/examples/basic/shared/greeter_interface.go#L63
// for context and details
func (CustomCostPlugin) GRPCClient(context context.Context, b *plugin.GRPCBroker, c *grpc.ClientConn) (interface{}, error) {
return &GRPCClient{client: pb.NewCustomCostsSourceClient(c)}, nil
}