{"modulePath":"github.com/GoCodeAlone/go-plugin","version":"v1.7.0","isLatest":true,"isStandardLibrary":false,"goos":"linux","goarch":"amd64","docs":"# package plugin\n\nThe plugin package exposes functions and helpers for communicating to plugins which are implemented as standalone binary applications.\n\nplugin.Client fully manages the lifecycle of executing the application, connecting to it, and returning the RPC client for dispensing plugins.\n\nplugin.Serve fully manages listeners to expose an RPC server from a binary that plugin.Client can connect to.\n\n## Constants\n\n```go\nconst (\n\t// EnvUnixSocketDir specifies the directory that _plugins_ should create unix\n\t// sockets in. Does not affect client behavior.\n\tEnvUnixSocketDir = \"PLUGIN_UNIX_SOCKET_DIR\"\n\n\t// EnvUnixSocketGroup specifies the owning, writable group to set for Unix\n\t// sockets created by _plugins_. Does not affect client behavior.\n\tEnvUnixSocketGroup = \"PLUGIN_UNIX_SOCKET_GROUP\"\n)\n```\n\n```go\nconst CoreProtocolVersion = 1\n```\nCoreProtocolVersion is the ProtocolVersion of the plugin system itself. We will increment this whenever we change any protocol behavior. This will invalidate any prior plugins but will at least allow us to iterate on the core in a safe way. We will do our best to do this very infrequently.\n\n```go\nconst GRPCServiceName = \"plugin\"\n```\nGRPCServiceName is the name of the service that the health check should return as passing.\n\n## Variables\n\n```go\nvar (\n\t// ErrProcessNotFound is returned when a client is instantiated to\n\t// reattach to an existing process and it isn't found.\n\tErrProcessNotFound = cmdrunner.ErrProcessNotFound\n\n\t// ErrChecksumsDoNotMatch is returned when binary's checksum doesn't match\n\t// the one provided in the SecureConfig.\n\tErrChecksumsDoNotMatch = errors.New(\"checksums did not match\")\n\n\t// ErrSecureNoChecksum is returned when an empty checksum is provided to the\n\t// SecureConfig.\n\tErrSecureConfigNoChecksum = errors.New(\"no checksum provided\")\n\n\t// ErrSecureNoHash is returned when a nil Hash object is provided to the\n\t// SecureConfig.\n\tErrSecureConfigNoHash = errors.New(\"no hash implementation provided\")\n\n\t// ErrSecureConfigAndReattach is returned when both Reattach and\n\t// SecureConfig are set.\n\tErrSecureConfigAndReattach = errors.New(\"only one of Reattach or SecureConfig can be set\")\n\n\t// ErrGRPCBrokerMuxNotSupported is returned when the client requests\n\t// multiplexing over the gRPC broker, but the plugin does not support the\n\t// feature. In most cases, this should be resolvable by updating and\n\t// rebuilding the plugin, or restarting the plugin with\n\t// ClientConfig.GRPCBrokerMultiplex set to false.\n\tErrGRPCBrokerMuxNotSupported = errors.New(\"client requested gRPC broker multiplexing but plugin does not support the feature\")\n)\n```\nError types\n\n```go\nvar Killed uint32 = 0\n```\nIf this is 1, then we've called CleanupClients. This can be used by plugin RPC implementations to change error behavior since you can expected network connection errors at this point. This should be read by using sync/atomic.\n\n## Functions\n\n```go\nfunc CleanupClients()\n```\nThis makes sure all the managed subprocesses are killed and properly logged. This should be called before the parent process running the plugins exits.\n\nThis must only be called \\_once\\_.\n\n```go\nfunc DefaultGRPCServer(opts []grpc.ServerOption) *grpc.Server\n```\nDefaultGRPCServer can be used with the \"GRPCServer\" field for Server as a default factory method to create a gRPC server with no extra options.\n\n```go\nfunc Discover(glob, dir string) ([]string, error)\n```\nDiscover discovers plugins that are in a given directory.\n\nThe directory doesn't need to be absolute. For example, \".\" will work fine.\n\nThis currently assumes any file matching the glob is a plugin. In the future this may be smarter about checking that a file is executable and so on.\n\nTODO: test\n\n```go\nfunc Serve(opts *ServeConfig)\n```\nServe serves the plugins given by ServeConfig.\n\nServe doesn't return until the plugin is done being executed. Any fixable errors will be output to os.Stderr and the process will exit with a status code of 1. Serve will panic for unexpected conditions where a user's fix is unknown.\n\nThis is the method that plugins should call in their main() functions.\n\n```go\nfunc ServeMux(m ServeMuxMap)\n```\nServeMux is like Serve, but serves multiple types of plugins determined by the argument given on the command-line.\n\nThis command doesn't return until the plugin is done being executed. Any errors are logged or output to stderr.\n\n```go\nfunc TestConn(t testing.T) (net.Conn, net.Conn)\n```\nTestConn is a helper function for returning a client and server net.Conn connected to each other.\n\n```go\nfunc TestGRPCConn(t testing.T, register func(*grpc.Server)) (*grpc.ClientConn, *grpc.Server)\n```\nTestGRPCConn returns a gRPC client conn and grpc server that are connected together and configured. The register function is used to register services prior to the Serve call. This is used to test gRPC connections.\n\n```go\nfunc TestPluginGRPCConn(t testing.T, multiplex bool, ps map[string]Plugin) (*GRPCClient, *GRPCServer)\n```\nTestPluginGRPCConn returns a plugin gRPC client and server that are connected together and configured. This is used to test gRPC connections.\n\n## Types\n\n```go\ntype BasicError struct {\n\tMessage string\n}\n```\nBasicError This is a type that wraps error types so that they can be messaged across RPC channels. Since \"error\" is an interface, we can't always gob-encode the underlying structure. This is a valid error interface implementer that we will push across.\n\n```go\nfunc NewBasicError(err error) *BasicError\n```\nNewBasicError is used to create a BasicError.\n\nerr is allowed to be nil.\n\n```go\nfunc (e *BasicError) Error() string\n```\n\n```go\ntype Client struct {\n\t// contains filtered or unexported fields\n}\n```\nClient handles the lifecycle of a plugin application. It launches plugins, connects to them, dispenses interface implementations, and handles killing the process.\n\nPlugin hosts should use one Client for each plugin executable. To dispense a plugin type, use the \\`Client.Client\\` function, and then cal \\`Dispense\\`. This awkward API is mostly historical but is used to split the client that deals with subprocess management and the client that does RPC management.\n\nSee NewClient and ClientConfig for using a Client.\n\n```go\nfunc NewClient(config *ClientConfig) (c *Client)\n```\nNewClient creates a new plugin client which manages the lifecycle of an external plugin and gets the address for the RPC connection.\n\nThe client must be cleaned up at some point by calling Kill(). If the client is a managed client (created with ClientConfig.Managed) you can just call CleanupClients at the end of your program and they will be properly cleaned.\n\n```go\nfunc (c *Client) Client() (ClientProtocol, error)\n```\nClient returns the protocol client for this connection.\n\nSubsequent calls to this will return the same client.\n\n```go\nfunc (c *Client) Exited() bool\n```\nTells whether or not the underlying process has exited.\n\n```go\nfunc (c *Client) ID() string\n```\nID returns a unique ID for the running plugin. By default this is the process ID (pid), but it could take other forms if RunnerFunc was provided.\n\n```go\nfunc (c *Client) Kill()\n```\nEnd the executing subprocess (if it is running) and perform any cleanup tasks necessary such as capturing any remaining logs and so on.\n\nThis method blocks until the process successfully exits.\n\nThis method can safely be called multiple times.\n\n```go\nfunc (c *Client) NegotiatedVersion() int\n```\nNegotiatedVersion returns the protocol version negotiated with the server. This is only valid after Start() is called.\n\n```go\nfunc (c *Client) Protocol() Protocol\n```\nProtocol returns the protocol of server on the remote end. This will start the plugin process if it isn't already started. Errors from starting the plugin are surpressed and ProtocolInvalid is returned. It is recommended you call Start explicitly before calling Protocol to ensure no errors occur.\n\n```go\nfunc (c *Client) ReattachConfig() *ReattachConfig\n```\nReattachConfig returns the information that must be provided to NewClient to reattach to the plugin process that this client started. This is useful for plugins that detach from their parent process.\n\nIf this returns nil then the process hasn't been started yet. Please call Start or Client before calling this.\n\nClients who specified a RunnerFunc will need to populate their own ReattachFunc in the returned ReattachConfig before it can be used.\n\n```go\nfunc (c *Client) Start() (addr net.Addr, err error)\n```\nStart the underlying subprocess, communicating with it to negotiate a port for RPC connections, and returning the address to connect via RPC.\n\nThis method is safe to call multiple times. Subsequent calls have no effect. Once a client has been started once, it cannot be started again, even if it was killed.\n\n```go\ntype ClientConfig struct {\n\t// HandshakeConfig is the configuration that must match servers.\n\tHandshakeConfig\n\n\t// Plugins are the plugins that can be consumed.\n\t// The implied version of this PluginSet is the Handshake.ProtocolVersion.\n\tPlugins PluginSet\n\n\t// VersionedPlugins is a map of PluginSets for specific protocol versions.\n\t// These can be used to negotiate a compatible version between client and\n\t// server. If this is set, Handshake.ProtocolVersion is not required.\n\tVersionedPlugins map[int]PluginSet\n\n\t// One of the following must be set, but not both.\n\t//\n\t// Cmd is the unstarted subprocess for starting the plugin. If this is\n\t// set, then the Client starts the plugin process on its own and connects\n\t// to it.\n\t//\n\t// Reattach is configuration for reattaching to an existing plugin process\n\t// that is already running. This isn't common.\n\tCmd      *exec.Cmd\n\tReattach *ReattachConfig\n\n\t// RunnerFunc allows consumers to provide their own implementation of\n\t// runner.Runner and control the context within which a plugin is executed.\n\t// The cmd argument will have been copied from the config and populated with\n\t// environment variables that a go-plugin server expects to read such as\n\t// AutoMTLS certs and the magic cookie key.\n\tRunnerFunc func(l hclog.Logger, cmd *exec.Cmd, tmpDir string) (runner.Runner, error)\n\n\t// SecureConfig is configuration for verifying the integrity of the\n\t// executable. It can not be used with Reattach.\n\tSecureConfig *SecureConfig\n\n\t// TLSConfig is used to enable TLS on the RPC client.\n\tTLSConfig *tls.Config\n\n\t// Managed represents if the client should be managed by the\n\t// plugin package or not. If true, then by calling CleanupClients,\n\t// it will automatically be cleaned up. Otherwise, the client\n\t// user is fully responsible for making sure to Kill all plugin\n\t// clients. By default the client is _not_ managed.\n\tManaged bool\n\n\t// The minimum and maximum port to use for communicating with\n\t// the subprocess. If not set, this defaults to 10,000 and 25,000\n\t// respectively.\n\tMinPort, MaxPort uint\n\n\t// StartTimeout is the timeout to wait for the plugin to say it\n\t// has started successfully.\n\tStartTimeout time.Duration\n\n\t// If non-nil, then the stderr of the client will be written to here\n\t// (as well as the log). This is the original os.Stderr of the subprocess.\n\t// This isn't the output of synced stderr.\n\tStderr io.Writer\n\n\t// SyncStdout, SyncStderr can be set to override the\n\t// respective os.Std* values in the plugin. Care should be taken to\n\t// avoid races here. If these are nil, then this will be set to\n\t// io.Discard.\n\tSyncStdout io.Writer\n\tSyncStderr io.Writer\n\n\t// AllowedProtocols is a list of allowed protocols.\n\t//\n\t// By setting this, you can cause an error immediately on plugin start\n\t// if an unsupported protocol is used with a good error message.\n\t//\n\t// If this isn't set at all (nil value), then only gRPC is accepted.\n\tAllowedProtocols []Protocol\n\n\t// Logger is the logger that the client will used. If none is provided,\n\t// it will default to hclog's default logger.\n\tLogger hclog.Logger\n\n\t// PluginLogBufferSize is the buffer size(bytes) to read from stderr for plugin log lines.\n\t// If this is 0, then the default of 64KB is used.\n\tPluginLogBufferSize int\n\n\t// AutoMTLS has the client and server automatically negotiate mTLS for\n\t// transport authentication. This ensures that only the original client will\n\t// be allowed to connect to the server, and all other connections will be\n\t// rejected. The client will also refuse to connect to any server that isn't\n\t// the original instance started by the client.\n\t//\n\t// In this mode of operation, the client generates a one-time use tls\n\t// certificate, sends the public x.509 certificate to the new server, and\n\t// the server generates a one-time use tls certificate, and sends the public\n\t// x.509 certificate back to the client. These are used to authenticate all\n\t// rpc connections between the client and server.\n\t//\n\t// Setting AutoMTLS to true implies that the server must support the\n\t// protocol, and correctly negotiate the tls certificates, or a connection\n\t// failure will result.\n\t//\n\t// The client should not set TLSConfig, nor should the server set a\n\t// TLSProvider, because AutoMTLS implies that a new certificate and tls\n\t// configuration will be generated at startup.\n\t//\n\t// You cannot Reattach to a server with this option enabled.\n\tAutoMTLS bool\n\n\t// GRPCDialOptions allows plugin users to pass custom grpc.DialOption\n\t// to create gRPC connections. This only affects plugins using the gRPC\n\t// protocol.\n\tGRPCDialOptions []grpc.DialOption\n\n\t// GRPCBrokerMultiplex turns on multiplexing for the gRPC broker. The gRPC\n\t// broker will multiplex all brokered gRPC servers over the plugin's original\n\t// listener socket instead of making a new listener for each server. The\n\t// go-plugin library currently only includes a Go implementation for the\n\t// server (i.e. plugin) side of gRPC broker multiplexing.\n\t//\n\t// Does not support reattaching.\n\t//\n\t// Multiplexed gRPC streams MUST be established sequentially, i.e. after\n\t// calling AcceptAndServe from one side, wait for the other side to Dial\n\t// before calling AcceptAndServe again.\n\tGRPCBrokerMultiplex bool\n\n\t// SkipHostEnv allows plugins to run without inheriting the parent process'\n\t// environment variables.\n\tSkipHostEnv bool\n\n\t// UnixSocketConfig configures additional options for any Unix sockets\n\t// that are created. Not normally required. Not supported on Windows.\n\tUnixSocketConfig *UnixSocketConfig\n\n\t// SkipLogParsing disables JSON log parsing for plugin stderr. When true,\n\t// each line is logged verbatim without attempting to unmarshal it as an\n\t// hclog JSON entry. This avoids the cost of JSON parsing for plugins that\n\t// are known not to emit structured logs.\n\tSkipLogParsing bool\n}\n```\nClientConfig is the configuration used to initialize a new plugin client. After being used to initialize a plugin client, that configuration must not be modified again.\n\n```go\ntype ClientProtocol interface {\n\tio.Closer\n\n\t// Dispense dispenses a new instance of the plugin with the given name.\n\tDispense(string) (any, error)\n\n\t// Ping checks that the client connection is still healthy.\n\tPing() error\n}\n```\nClientProtocol is an interface that must be implemented for new plugin protocols to be clients.\n\n```go\ntype GRPCBroker struct {\n\tsync.Mutex\n\t// contains filtered or unexported fields\n}\n```\nGRPCBroker is responsible for brokering connections by unique ID.\n\nIt is used by plugins to create multiple gRPC connections and data streams between the plugin process and the host process.\n\nThis allows a plugin to request a channel with a specific ID to connect to or accept a connection from, and the broker handles the details of holding these channels open while they're being negotiated.\n\nThe Plugin interface has access to these for both Server and Client. The broker can be used by either (optionally) to reserve and connect to new streams. This is useful for complex args and return values, or anything else you might need a data stream for.\n\n```go\nfunc (b *GRPCBroker) Accept(id uint32) (net.Listener, error)\n```\nAccept accepts a connection by ID.\n\nThis should not be called multiple times with the same ID at one time.\n\n```go\nfunc (b *GRPCBroker) AcceptAndServe(id uint32, newGRPCServer func([]grpc.ServerOption) *grpc.Server)\n```\nAcceptAndServe is used to accept a specific stream ID and immediately serve a gRPC server on that stream ID. This is used to easily serve complex arguments. Each AcceptAndServe call opens a new listener socket and sends the connection info down the stream to the dialer. Since a new connection is opened every call, these calls should be used sparingly. Multiple gRPC server implementations can be registered to a single AcceptAndServe call.\n\n```go\nfunc (b *GRPCBroker) Close() error\n```\nClose closes the stream and all servers.\n\n```go\nfunc (b *GRPCBroker) Dial(id uint32) (conn *grpc.ClientConn, err error)\n```\nDial opens a connection by ID using the broker's default dial options.\n\n```go\nfunc (b *GRPCBroker) DialWithOptions(id uint32, opts ...grpc.DialOption) (conn *grpc.ClientConn, err error)\n```\nDialWithOptions opens a connection by ID, passing the provided gRPC dial options in addition to the broker's default dial options.\n\n```go\nfunc (m *GRPCBroker) NextId() uint32\n```\nNextId returns a unique ID to use next.\n\nIt is possible for very long-running plugin hosts to wrap this value, though it would require a very large amount of calls. In practice we've never seen it happen.\n\n```go\nfunc (m *GRPCBroker) Run()\n```\nRun starts the brokering and should be executed in a goroutine, since it blocks forever, or until the session closes.\n\nUses of GRPCBroker never need to call this. It is called internally by the plugin host/client.\n\n```go\ntype GRPCClient struct {\n\tConn    *grpc.ClientConn\n\tPlugins map[string]Plugin\n\t// contains filtered or unexported fields\n}\n```\nGRPCClient connects to a GRPCServer over gRPC to dispense plugin types.\n\n```go\nfunc (c *GRPCClient) Close() error\n```\nClientProtocol impl.\n\n```go\nfunc (c *GRPCClient) Dispense(name string) (any, error)\n```\nClientProtocol impl.\n\n```go\nfunc (c *GRPCClient) Ping() error\n```\nClientProtocol impl.\n\n```go\ntype GRPCServer struct {\n\t// Plugins are the list of plugins to serve.\n\tPlugins map[string]Plugin\n\n\t// Server is the actual server that will accept connections. This\n\t// will be used for plugin registration as well.\n\tServer func([]grpc.ServerOption) *grpc.Server\n\n\t// TLS should be the TLS configuration if available. If this is nil,\n\t// the connection will not have transport security.\n\tTLS *tls.Config\n\n\t// DoneCh is the channel that is closed when this server has exited.\n\tDoneCh chan struct{}\n\n\t// Stdout/StderrLis are the readers for stdout/stderr that will be copied\n\t// to the stdout/stderr connection that is output.\n\tStdout io.Reader\n\tStderr io.Reader\n\t// contains filtered or unexported fields\n}\n```\nGRPCServer is a ServerType implementation that serves plugins over gRPC. This allows plugins to easily be written for other languages.\n\nThe GRPCServer outputs a custom configuration as a base64-encoded JSON structure represented by the GRPCServerConfig config structure.\n\n```go\nfunc (s *GRPCServer) Config() string\n```\nConfig is the GRPCServerConfig encoded as JSON then base64.\n\n```go\nfunc (s *GRPCServer) GracefulStop()\n```\nGracefulStop calls GracefulStop on the underlying grpc.Server and Close on the underlying grpc.Broker if present.\n\n```go\nfunc (s *GRPCServer) Init() error\n```\nServerProtocol impl.\n\n```go\nfunc (s *GRPCServer) Serve(lis net.Listener)\n```\n\n```go\nfunc (s *GRPCServer) Stop()\n```\nStop calls Stop on the underlying grpc.Server and Close on the underlying grpc.Broker if present.\n\n```go\ntype GRPCServerConfig struct {\n\tStdoutAddr string `json:\"stdout_addr\"`\n\tStderrAddr string `json:\"stderr_addr\"`\n}\n```\nGRPCServerConfig is the extra configuration passed along for consumers to facilitate using GRPC plugins.\n\n```go\ntype HandshakeConfig struct {\n\t// ProtocolVersion is the version that clients must match on to\n\t// agree they can communicate. This should match the ProtocolVersion\n\t// set on ClientConfig when using a plugin.\n\t// This field is not required if VersionedPlugins are being used in the\n\t// Client or Server configurations.\n\tProtocolVersion uint\n\n\t// MagicCookieKey and value are used as a very basic verification\n\t// that a plugin is intended to be launched. This is not a security\n\t// measure, just a UX feature. If the magic cookie doesn't match,\n\t// we show human-friendly output.\n\tMagicCookieKey   string\n\tMagicCookieValue string\n}\n```\nHandshakeConfig is the configuration used by client and servers to handshake before starting a plugin connection. This is embedded by both ServeConfig and ClientConfig.\n\nIn practice, the plugin host creates a HandshakeConfig that is exported and plugins then can easily consume it.\n\n```go\ntype Plugin interface {\n\t// GRPCServer should register this plugin for serving with the\n\t// given GRPCServer. Unlike Plugin.Server, this is only called once\n\t// since gRPC plugins serve singletons.\n\tGRPCServer(*GRPCBroker, *grpc.Server) error\n\n\t// GRPCClient should return the interface implementation for the plugin\n\t// you're serving via gRPC. The provided context will be canceled by\n\t// go-plugin in the event of the plugin process exiting.\n\tGRPCClient(context.Context, *GRPCBroker, *grpc.ClientConn) (any, error)\n}\n```\nPlugin is the interface that is implemented to serve/connect to a plugin over gRPC.\n\n```go\ntype PluginSet map[string]Plugin\n```\nPluginSet is a set of plugins provided to be registered in the plugin server.\n\n```go\ntype Protocol string\n```\nProtocol is an enum representing the types of protocols.\n\n```go\nconst (\n\tProtocolInvalid Protocol = \"\"\n\tProtocolGRPC    Protocol = \"grpc\"\n)\n```\n\n```go\ntype ReattachConfig struct {\n\tProtocol        Protocol\n\tProtocolVersion int\n\tAddr            net.Addr\n\tPid             int\n\n\t// ReattachFunc allows consumers to provide their own implementation of\n\t// runner.AttachedRunner and attach to something other than a plain process.\n\t// At least one of Pid or ReattachFunc must be set.\n\tReattachFunc runner.ReattachFunc\n\n\t// Test is set to true if this is reattaching to to a plugin in \"test mode\"\n\t// (see ServeConfig.Test). In this mode, client.Kill will NOT kill the\n\t// process and instead will rely on the plugin to terminate itself. This\n\t// should not be used in non-test environments.\n\tTest bool\n}\n```\nReattachConfig is used to configure a client to reattach to an already-running plugin process. You can retrieve this information by calling ReattachConfig on Client.\n\n```go\ntype SecureConfig struct {\n\tChecksum []byte\n\tHash     hash.Hash\n}\n```\nSecureConfig is used to configure a client to verify the integrity of an executable before running. It does this by verifying the checksum is expected. Hash is used to specify the hashing method to use when checksumming the file.  The configuration is verified by the client by calling the SecureConfig.Check() function.\n\nThe host process should ensure the checksum was provided by a trusted and authoritative source. The binary should be installed in such a way that it can not be modified by an unauthorized user between the time of this check and the time of execution.\n\n```go\nfunc (s *SecureConfig) Check(filePath string) (bool, error)\n```\nCheck takes the filepath to an executable and returns true if the checksum of the file matches the checksum provided in the SecureConfig.\n\n```go\ntype ServeConfig struct {\n\t// HandshakeConfig is the configuration that must match clients.\n\tHandshakeConfig\n\n\t// TLSProvider is a function that returns a configured tls.Config.\n\tTLSProvider func() (*tls.Config, error)\n\n\t// Plugins are the plugins that are served.\n\t// The implied version of this PluginSet is the Handshake.ProtocolVersion.\n\tPlugins PluginSet\n\n\t// VersionedPlugins is a map of PluginSets for specific protocol versions.\n\t// These can be used to negotiate a compatible version between client and\n\t// server. If this is set, Handshake.ProtocolVersion is not required.\n\tVersionedPlugins map[int]PluginSet\n\n\t// GRPCServer should be non-nil to enable serving the plugins over\n\t// gRPC. This is a function to create the server when needed with the\n\t// given server options. The server options populated by go-plugin will\n\t// be for TLS if set. You may modify the input slice.\n\t//\n\t// Note that the grpc.Server will automatically be registered with\n\t// the gRPC health checking service. This is not optional since go-plugin\n\t// relies on this to implement Ping().\n\tGRPCServer func([]grpc.ServerOption) *grpc.Server\n\n\t// Logger is used to pass a logger into the server. If none is provided the\n\t// server will create a default logger.\n\tLogger hclog.Logger\n\n\t// Test, if non-nil, will put plugin serving into \"test mode\". This is\n\t// meant to be used as part of `go test` within a plugin's codebase to\n\t// launch the plugin in-process and output a ReattachConfig.\n\t//\n\t// This changes the behavior of the server in a number of ways to\n\t// accomodate the expectation of running in-process:\n\t//\n\t//   * The handshake cookie is not validated.\n\t//   * Stdout/stderr will receive plugin reads and writes\n\t//   * Connection information will not be sent to stdout\n\t//\n\tTest *ServeTestConfig\n}\n```\nServeConfig configures what sorts of plugins are served.\n\n```go\ntype ServeMuxMap map[string]*ServeConfig\n```\nServeMuxMap is the type that is used to configure ServeMux\n\n```go\ntype ServeTestConfig struct {\n\t// Context, if set, will force the plugin serving to end when cancelled.\n\t// This is only a test configuration because the non-test configuration\n\t// expects to take over the process and therefore end on an interrupt or\n\t// kill signal. For tests, we need to kill the plugin serving routinely\n\t// and this provides a way to do so.\n\t//\n\t// If you want to wait for the plugin process to close before moving on,\n\t// you can wait on CloseCh.\n\tContext context.Context\n\n\t// If this channel is non-nil, we will send the ReattachConfig via\n\t// this channel. This can be encoded (via JSON recommended) to the\n\t// plugin client to attach to this plugin.\n\tReattachConfigCh chan\u003c- *ReattachConfig\n\n\t// CloseCh, if non-nil, will be closed when serving exits. This can be\n\t// used along with Context to determine when the server is fully shut down.\n\t// If this is not set, you can still use Context on its own, but note there\n\t// may be a period of time between canceling the context and the plugin\n\t// server being shut down.\n\tCloseCh chan\u003c- struct{}\n\n\t// SyncStdio, if true, will enable the client side \"SyncStdout/Stderr\"\n\t// functionality to work. This defaults to false because the implementation\n\t// of making this work within test environments is particularly messy\n\t// and SyncStdio functionality is fairly rare, so we default to the simple\n\t// scenario.\n\tSyncStdio bool\n}\n```\nServeTestConfig configures plugin serving for test mode. See ServeConfig.Test.\n\n```go\ntype ServerProtocol interface {\n\t// Init is called once to configure and initialize the protocol, but\n\t// not start listening. This is the point at which all validation should\n\t// be done and errors returned.\n\tInit() error\n\n\t// Config is extra configuration to be outputted to stdout. This will\n\t// be automatically base64 encoded to ensure it can be parsed properly.\n\t// This can be an empty string if additional configuration is not needed.\n\tConfig() string\n\n\t// Serve is called to serve connections on the given listener. This should\n\t// continue until the listener is closed.\n\tServe(net.Listener)\n}\n```\nServerProtocol is an interface that must be implemented for new plugin protocols to be servers.\n\n```go\ntype UnixSocketConfig struct {\n\t// If set, go-plugin will change the owner of any Unix sockets created to\n\t// this group, and set them as group-writable. Can be a name or gid. The\n\t// client process must be a member of this group or chown will fail.\n\tGroup string\n\n\t// TempDir specifies the base directory to use when creating a plugin-specific\n\t// temporary directory. It is expected to already exist and be writable. If\n\t// not set, defaults to the directory chosen by os.MkdirTemp.\n\tTempDir string\n\t// contains filtered or unexported fields\n}\n```\n\n","path":"github.com/GoCodeAlone/go-plugin","name":"plugin","synopsis":"The plugin package exposes functions and helpers for communicating to plugins which are implemented as standalone binary applications.","isRedistributable":true}
