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