Documentation
¶
Index ¶
Constants ¶
View Source
const ( // MessageStatusOK is the status code for a successful message. MessageStatusOK = iota // MessageStatusErrDecodeFailed is the status code for a message that failed to decode. MessageStatusErrDecodeFailed // MessageStatusErrEncodeFailed is the status code for a message that failed to encode. MessageStatusErrEncodeFailed // MessageStatusSystemReservedMax is the maximum value for a system reserved status code. MessageStatusSystemReservedMax = 99 )
Variables ¶
View Source
var ErrShutdown = errors.New("connection is shut down")
ErrShutdown will be returned from Execute and Close if the client is or is about to be shut down.
View Source
var ErrTimeoutWaitingForServer = errors.New("timed out waiting for server to start")
ErrTimeoutWaitingForServer is returned on timeouts starting the server.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client[Q, R any] struct { // contains filtered or unexported fields }
func StartClient ¶
func StartClient[Q, R any](opts ClientOptions[Q, R]) (*Client[Q, R], error)
type ClientOptions ¶
type ClientOptions[Q, R any] struct { ClientRawOptions Codec codecs.Codec[Q, R] }
type ClientRaw ¶
type ClientRaw struct {
// contains filtered or unexported fields
}
func StartClientRaw ¶
func StartClientRaw(opts ClientRawOptions) (*ClientRaw, error)
type ClientRawOptions ¶
type ClientRawOptions struct {
// Version number passed to the server.
Version uint8
// The server to start.
Cmd string
// The arguments to pass to the command.
Args []string
// Environment variables to pass to the command.
// These will be merged with the environment variables of the current process,
// vallues in this slice have precedence.
// A slice of strings of the form "key=value"
Env []string
// Dir specifies the working directory of the command.
// If Dir is the empty string, the command runs in the
// calling process's current directory.
Dir string
// Callback for messages received from server without an ID (e.g. log message).
OnMessage func(Message)
// The timeout for the client.
Timeout time.Duration
}
type Dispatcher ¶
type ServerOptions ¶
type ServerOptions[Q, R any] struct { Call func(Dispatcher, Q) R Codec codecs.Codec[R, Q] }
ServerOptions is the options for a server.
type ServerRaw ¶
type ServerRaw struct {
// contains filtered or unexported fields
}
ServerRaw is a RPC server handling raw messages with a header and []byte body. See Server for a generic, typed version.
func NewServerRaw ¶
func NewServerRaw(opts ServerRawOptions) (*ServerRaw, error)
NewServerRaw creates a new Server. using the given options.
type ServerRawOptions ¶
type ServerRawOptions struct {
// Call is the message exhcange between the client and server.
// Note that any error returned by this function will be treated as a fatal error and the server is stopped.
// Validation errors etc. should be returned in the response message.
// The Dispatcher can be used to send messages to the client outside of the request/response loop, e.g. log messages.
// Note that these messages can not have an ID.
Call func(Dispatcher, Message) (Message, error)
}
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
servers/raw
module
|
|
|
servers/readmeexample
module
|
|
|
servers/typed
module
|
Click to show internal directories.
Click to hide internal directories.