{"modulePath":"github.com/bep/execrpc","version":"v0.10.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package execrpc\n\n## Constants\n\n```go\nconst (\n\t// MessageStatusOK is the status code for a successful and complete message exchange.\n\tMessageStatusOK = iota\n\n\t// MessageStatusContinue is the status code for a message that should continue the conversation.\n\tMessageStatusContinue\n\n\t// MessageStatusInitServer is the status code for a message used to initialize/configure the server.\n\tMessageStatusInitServer\n\n\t// MessageStatusErrDecodeFailed is the status code for a message that failed to decode.\n\tMessageStatusErrDecodeFailed\n\t// MessageStatusErrEncodeFailed is the status code for a message that failed to encode.\n\tMessageStatusErrEncodeFailed\n\t// MessageStatusErrInitServerFailed is the status code for a message that failed to initialize the server.\n\tMessageStatusErrInitServerFailed\n\n\t// MessageStatusSystemReservedMax is the maximum value for a system reserved status code.\n\tMessageStatusSystemReservedMax = 99\n)\n```\n\n## Variables\n\n```go\nvar (\n\t// ErrTimeoutWaitingForServer is returned on timeouts starting the server.\n\tErrTimeoutWaitingForServer = errors.New(\"timed out waiting for server to start\")\n\t// ErrTimeoutWaitingForCall is returned on timeouts waiting for a call to complete.\n\tErrTimeoutWaitingForCall = errors.New(\"timed out waiting for call to complete\")\n)\n```\n\n```go\nvar ErrShutdown = errors.New(\"connection is shut down\")\n```\nErrShutdown will be returned from Execute and Close if the client is or is about to be shut down.\n\n## Types\n\n```go\ntype Call[Q, M, R any] struct {\n\tRequest Q\n\t// contains filtered or unexported fields\n}\n```\nCall is the request/response exchange between the client and server. Note that the stream parameter S is optional, set it to any if not used.\n\n```go\nfunc (c *Call[Q, M, R]) Close(drop bool, r R)\n```\nClose closes the call and sends andy buffered messages and the receipt back to the client. If drop is true, the buffered messages are dropped. Note that drop is only relevant if the server is configured with DelayDelivery set to true.\n\n```go\nfunc (c *Call[Q, M, R]) Enqueue(rr ...M)\n```\nEnqueue enqueues one or more messages to be sent back to the client.\n\n```go\nfunc (c *Call[Q, M, R]) Receipt() \u003c-chan R\n```\n\n```go\nfunc (c *Call[Q, M, R]) SendRaw(ms ...Message)\n```\nSendRaw sends one or more messages back to the client that is not part of the request/response exchange. These messages must have ID 0.\n\n```go\ntype Client[C, Q, M, R any] struct {\n\t// contains filtered or unexported fields\n}\n```\nClient is a strongly typed RPC client.\n\n```go\nfunc StartClient[C, Q, M, R any](opts ClientOptions[C, Q, M, R]) (*Client[C, Q, M, R], error)\n```\nStartClient starts a client for the given options.\n\n```go\nfunc (c *Client[C, Q, M, R]) Close() error\n```\nClose closes the client.\n\n```go\nfunc (c *Client[C, Q, M, R]) Execute(r Q) Result[M, R]\n```\nExecute sends the request to the server and returns the result. You should check Err() both before and after reading from the messages and receipt channels.\n\n```go\nfunc (c *Client[C, Q, M, R]) MessagesRaw() \u003c-chan Message\n```\nMessagesRaw returns the raw messages from the server. These are not connected to the request-response flow, typically used for log messages etc.\n\n```go\ntype ClientOptions[C, Q, M, R any] struct {\n\tClientRawOptions\n\n\t// The configuration to pass to the server.\n\tConfig C\n\n\t// The codec to use.\n\tCodec codecs.Codec\n}\n```\nClientOptions are options for the client.\n\n```go\ntype ClientRaw struct {\n\n\t// Messages from the server that are not part of the request-response flow.\n\tMessages chan Message\n\t// contains filtered or unexported fields\n}\n```\nClientRaw is a raw RPC client. Raw means that the client doesn't do any type conversion, a byte slice is what you get.\n\n```go\nfunc StartClientRaw(opts ClientRawOptions) (*ClientRaw, error)\n```\nStartClientRaw starts a untyped client client for the given options.\n\n```go\nfunc (c *ClientRaw) Close() error\n```\nClose closes the server connection and waits for the server process to quit.\n\n```go\nfunc (c *ClientRaw) Execute(withMessage func(m *Message), messages chan\u003c- Message) error\n```\nExecute sends body to the server and sends any messages to the messages channel. It's safe to call Execute from multiple goroutines. The messages channel wil be closed when the call is done.\n\n```go\ntype ClientRawOptions struct {\n\t// Version number passed to the server.\n\tVersion uint16\n\n\t// The server to start.\n\tCmd string\n\n\t// The arguments to pass to the command.\n\tArgs []string\n\n\t// Environment variables to pass to the command.\n\t// These will be merged with the environment variables of the current process,\n\t// vallues in this slice have precedence.\n\t// A slice of strings of the form \"key=value\"\n\tEnv []string\n\n\t// Dir specifies the working directory of the command.\n\t// If Dir is the empty string, the command runs in the\n\t// calling process's current directory.\n\tDir string\n\n\t// The timeout for the client.\n\tTimeout time.Duration\n}\n```\nClientRawOptions are options for the raw part of the client.\n\n```go\ntype Dispatcher interface {\n\t// SendMessage sends one or more message back to the client.\n\tSendMessage(...Message)\n}\n```\nDispatcher is the interface for dispatching messages to the client.\n\n```go\ntype Header struct {\n\tID      uint32\n\tVersion uint16\n\tStatus  uint16\n\tSize    uint32\n}\n```\nHeader is the header of a message. ID and Size are set by the system. Status may be set by the system.\n\n```go\nfunc (h *Header) Read(r io.Reader) error\n```\nRead reads the header from the reader.\n\n```go\nfunc (h Header) Write(w io.Writer) error\n```\nWrite writes the header to the writer.\n\n```go\ntype Identity struct {\n\tLastModified int64  `json:\"lastModified\"`\n\tETag         string `json:\"eTag\"`\n\tSize         uint32 `json:\"size\"`\n}\n```\nIdentity holds the modified time (Unix seconds) and a 64-bit checksum.\n\n```go\nfunc (i Identity) GetELastModified() int64\n```\nGetELastModified returns the last modified time.\n\n```go\nfunc (i Identity) GetESize() uint32\n```\nGetESize returns the size.\n\n```go\nfunc (i Identity) GetETag() string\n```\nGetETag returns the checksum.\n\n```go\nfunc (i *Identity) SetELastModified(t int64)\n```\nSetELastModified sets the last modified time.\n\n```go\nfunc (i *Identity) SetESize(s uint32)\n```\nSetESize sets the size.\n\n```go\nfunc (i *Identity) SetETag(s string)\n```\nSetETag sets the checksum.\n\n```go\ntype LastModifiedProvider interface {\n\tGetELastModified() int64\n\tSetELastModified(int64)\n}\n```\nLastModifiedProvider is the interface for a type that can provide a last modified time.\n\n```go\ntype Message struct {\n\tHeader Header\n\tBody   []byte\n}\n```\nMessage is what gets sent to and from the server.\n\n```go\nfunc (m *Message) Read(r io.Reader) error\n```\n\n```go\nfunc (m *Message) Write(w io.Writer) error\n```\n\n```go\ntype ProtocolInfo struct {\n\t// The version passed down from the client.\n\t// This usually represents a major version,\n\t// so any increment should be considered a breaking change.\n\tVersion uint16 `json:\"version\"`\n}\n```\nProtocolInfo is the protocol information passed to the server's Init function.\n\n```go\ntype Result[M, R any] struct {\n\t// contains filtered or unexported fields\n}\n```\nResult is the result of a request with zero or more messages and the receipt.\n\n```go\nfunc (r Result[M, R]) Err() error\n```\nErr returns any error.\n\n```go\nfunc (r Result[M, R]) Messages() \u003c-chan M\n```\nMessages returns the messages from the server.\n\n```go\nfunc (r Result[M, R]) Receipt() \u003c-chan R\n```\nReceipt returns the receipt from the server.\n\n```go\ntype Server[C, Q, M, R any] struct {\n\t*ServerRaw\n\t// contains filtered or unexported fields\n}\n```\nServer is a stringly typed server for requests of type Q and responses of tye R.\n\n```go\nfunc NewServer[C, Q, M, R any](opts ServerOptions[C, Q, M, R]) (*Server[C, Q, M, R], error)\n```\nNewServer creates a new Server. using the given options.\n\n```go\nfunc (s *Server[C, Q, M, R]) Start() error\n```\n\n```go\ntype ServerOptions[C, Q, M, R any] struct {\n\t// Init is the function that will be called when the server is started.\n\t// It can be used to initialize the server with the given configuration.\n\t// If an error is returned, the server will stop.\n\tInit func(C, ProtocolInfo) error\n\n\t// Handle is the function that will be called when a request is received.\n\tHandle func(*Call[Q, M, R])\n\n\t// Codec is the codec that will be used to encode and decode requests, messages and receipts.\n\t// The client will tell the server what codec is in use, so in most cases you should just leave this unset.\n\tCodec codecs.Codec\n\n\t// GetHasher returns the hash instance to be used for the response body\n\t// If it's not set or it returns nil, no hash will be calculated.\n\tGetHasher func() hash.Hash\n\n\t// Delay delivery of messages to the client until Close is called.\n\t// Close takes a drop parameter that will drop any buffered messages.\n\t// This can be useful if you want to check the server generated ETag,\n\t// maybe the client already has this data.\n\tDelayDelivery bool\n}\n```\nServerOptions is the options for a server.\n\n```go\ntype ServerRaw struct {\n\t// contains filtered or unexported fields\n}\n```\nServerRaw is a RPC server handling raw messages with a header and \\[]byte body. See Server for a generic, typed version.\n\n```go\nfunc NewServerRaw(opts ServerRawOptions) (*ServerRaw, error)\n```\nNewServerRaw creates a new Server using the given options.\n\n```go\nfunc (s *ServerRaw) Start() error\n```\nStart sets upt the server communication and starts the server loop.\n\n```go\ntype ServerRawOptions struct {\n\t// Call is the message exhcange between the client and server.\n\t// Note that any error returned by this function will be treated as a fatal error and the server is stopped.\n\t// Validation errors etc. should be returned in the response message.\n\t// Message passed to the Dispatcher as part of the request/response must\n\t// use the same ID as the request.\n\t// ID 0 is reserved for standalone messages (e.g. log messages).\n\tCall func(Message, Dispatcher) error\n}\n```\nServerRawOptions is the options for a raw portion of the server.\n\n```go\ntype SizeProvider interface {\n\tGetESize() uint32\n\tSetESize(uint32)\n}\n```\nSizeProvider is the interface for a type that can provide a size.\n\n```go\ntype TagProvider interface {\n\tGetETag() string\n\tSetETag(string)\n}\n```\nTagProvider is the interface for a type that can provide a eTag.\n\n","path":"github.com/bep/execrpc","name":"execrpc","synopsis":"","isRedistributable":true}
