plugin_interface.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. package plugin
  2. import (
  3. "context"
  4. "github.com/hashicorp/go-plugin"
  5. "github.com/opencost/opencost/core/pkg/model/pb"
  6. grpc "google.golang.org/grpc"
  7. )
  8. // plugin interface
  9. type CustomCostSource interface {
  10. GetCustomCosts(req *pb.CustomCostRequest) []*pb.CustomCostResponse
  11. }
  12. type CustomCostPlugin struct {
  13. plugin.Plugin
  14. // Impl Injection
  15. Impl CustomCostSource
  16. }
  17. // this method is called for as part of the reference plugin implementation
  18. // see https://github.com/hashicorp/go-plugin/blob/main/examples/basic/shared/greeter_interface.go#L59
  19. // for context and details
  20. func (p *CustomCostPlugin) GRPCServer(broker *plugin.GRPCBroker, s *grpc.Server) error {
  21. pb.RegisterCustomCostsSourceServer(s, &GRPCServer{Impl: p.Impl})
  22. return nil
  23. }
  24. // this method is called for as part of the reference plugin implementation
  25. // see https://github.com/hashicorp/go-plugin/blob/main/examples/basic/shared/greeter_interface.go#L63
  26. // for context and details
  27. func (CustomCostPlugin) GRPCClient(context context.Context, b *plugin.GRPCBroker, c *grpc.ClientConn) (interface{}, error) {
  28. return &GRPCClient{client: pb.NewCustomCostsSourceClient(c)}, nil
  29. }