Documentation
¶
Index ¶
Constants ¶
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 ¶
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.
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 }
Client is a strongly typed RPC client.
func StartClient ¶
func StartClient[Q, R any](opts ClientOptions[Q, R]) (*Client[Q, R], error)
StartClient starts a client for the given options.
type ClientOptions ¶
type ClientOptions[Q, R any] struct { ClientRawOptions Codec codecs.Codec[Q, R] }
ClientOptions are options for the client.
type ClientRaw ¶
type ClientRaw struct {
// contains filtered or unexported fields
}
ClientRaw is a raw RPC client. Raw means that the client doesn't do any type conversion, a byte slice is what you get.
func StartClientRaw ¶
func StartClientRaw(opts ClientRawOptions) (*ClientRaw, error)
StartClientRaw starts a untyped client client for the given options.
type ClientRawOptions ¶
type ClientRawOptions struct {
// Version number passed to the server.
Version uint16
// 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
}
ClientRawOptions are options for the raw part of the client.
type Dispatcher ¶
type Dispatcher interface {
// Send sends one or more message back to the client.
// This is normally used for log messages and similar,
// and these messages should have a zero (0) ID.
Send(...Message) error
}
Dispatcher is the interface for dispatching standalone messages to the client, e.g. log messages.
type Header ¶
Header is the header of a message. ID and Size are set by the system.
type ServerOptions ¶
type ServerOptions[Q, R any] struct { // Call is the function that will be called when a request is received. Call func(Dispatcher, Q) R // Codec is the codec that will be used to encode and decode requests and responses. // The client will tell the server what codec is in use, so in most cases you should just leave this unset. 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 must have ID 0.
Call func(Dispatcher, Message) (Message, error)
}
ServerRawOptions is the options for a raw portion of the server.
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
servers/raw
module
|
|
|
servers/readmeexample
module
|
|
|
servers/typed
module
|