protocol.go 1.2 KB

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