github.com/yoheimuta/protolint@v0.49.8-0.20240515023657-4ecaebb7575d/internal/addon/plugin/shared/config.go (about)

     1  package shared
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/yoheimuta/protolint/internal/addon/plugin/proto"
     7  
     8  	"github.com/hashicorp/go-plugin"
     9  	"google.golang.org/grpc"
    10  )
    11  
    12  // Handshake is a common handshake that is shared by plugin and host.
    13  var Handshake = plugin.HandshakeConfig{
    14  	ProtocolVersion:  1,
    15  	MagicCookieKey:   "BASIC_PLUGIN",
    16  	MagicCookieValue: "hello",
    17  }
    18  
    19  // PluginMap is the map of plugins we can dispense.
    20  var PluginMap = map[string]plugin.Plugin{
    21  	"ruleSet": &RuleSetGRPCPlugin{},
    22  }
    23  
    24  // RuleSetGRPCPlugin is the implementation of plugin.GRPCPlugin so we can serve/consume this.
    25  type RuleSetGRPCPlugin struct {
    26  	plugin.Plugin
    27  	Impl RuleSet
    28  }
    29  
    30  // GRPCServer registers this plugin.
    31  func (p *RuleSetGRPCPlugin) GRPCServer(broker *plugin.GRPCBroker, s *grpc.Server) error {
    32  	proto.RegisterRuleSetServiceServer(s, &GRPCServer{server: p.Impl})
    33  	return nil
    34  }
    35  
    36  // GRPCClient returns the interface implementation for the plugin.
    37  func (p *RuleSetGRPCPlugin) GRPCClient(ctx context.Context, broker *plugin.GRPCBroker, c *grpc.ClientConn) (interface{}, error) {
    38  	return &GRPCClient{client: proto.NewRuleSetServiceClient(c)}, nil
    39  }