github.com/hashicorp/go-plugin@v1.6.0/protocol.go (about)

     1  // Copyright (c) HashiCorp, Inc.
     2  // SPDX-License-Identifier: MPL-2.0
     3  
     4  package plugin
     5  
     6  import (
     7  	"io"
     8  	"net"
     9  )
    10  
    11  // Protocol is an enum representing the types of protocols.
    12  type Protocol string
    13  
    14  const (
    15  	ProtocolInvalid Protocol = ""
    16  	ProtocolNetRPC  Protocol = "netrpc"
    17  	ProtocolGRPC    Protocol = "grpc"
    18  )
    19  
    20  // ServerProtocol is an interface that must be implemented for new plugin
    21  // protocols to be servers.
    22  type ServerProtocol interface {
    23  	// Init is called once to configure and initialize the protocol, but
    24  	// not start listening. This is the point at which all validation should
    25  	// be done and errors returned.
    26  	Init() error
    27  
    28  	// Config is extra configuration to be outputted to stdout. This will
    29  	// be automatically base64 encoded to ensure it can be parsed properly.
    30  	// This can be an empty string if additional configuration is not needed.
    31  	Config() string
    32  
    33  	// Serve is called to serve connections on the given listener. This should
    34  	// continue until the listener is closed.
    35  	Serve(net.Listener)
    36  }
    37  
    38  // ClientProtocol is an interface that must be implemented for new plugin
    39  // protocols to be clients.
    40  type ClientProtocol interface {
    41  	io.Closer
    42  
    43  	// Dispense dispenses a new instance of the plugin with the given name.
    44  	Dispense(string) (interface{}, error)
    45  
    46  	// Ping checks that the client connection is still healthy.
    47  	Ping() error
    48  }