Documentation
¶
Index ¶
- Constants
- Variables
- type Call
- type Client
- type ClientOptions
- type ClientRaw
- type ClientRawOptions
- type Dispatcher
- type Header
- type Identity
- type LastModifiedProvider
- type Message
- type ProtocolInfo
- type Result
- type Server
- type ServerOptions
- type ServerRaw
- type ServerRawOptions
- type SizeProvider
- type TagProvider
Constants ¶
const ( // MessageStatusOK is the status code for a successful and complete message exchange. MessageStatusOK = iota // MessageStatusContinue is the status code for a message that should continue the conversation. MessageStatusContinue // MessageStatusInitServer is the status code for a message used to initialize/configure the server. MessageStatusInitServer // 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 // MessageStatusErrInitServerFailed is the status code for a message that failed to initialize the server. MessageStatusErrInitServerFailed // MessageStatusSystemReservedMax is the maximum value for a system reserved status code. MessageStatusSystemReservedMax = 99 )
Variables ¶
var ( // ErrTimeoutWaitingForServer is returned on timeouts starting the server. ErrTimeoutWaitingForServer = errors.New("timed out waiting for server to start") // ErrTimeoutWaitingForCall is returned on timeouts waiting for a call to complete. ErrTimeoutWaitingForCall = errors.New("timed out waiting for call to complete") )
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.
Functions ¶
This section is empty.
Types ¶
type Call ¶ added in v0.8.0
type Call[Q, M, R any] struct { Request Q // contains filtered or unexported fields }
Call 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.
func (*Call[Q, M, R]) Close ¶ added in v0.8.0
Close 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.
type Client ¶
type Client[C, Q, M, R any] struct { // contains filtered or unexported fields }
Client is a strongly typed RPC client.
func StartClient ¶
func StartClient[C, Q, M, R any](opts ClientOptions[C, Q, M, R]) (*Client[C, Q, M, R], error)
StartClient starts a client for the given options.
func (*Client[C, Q, M, R]) Execute ¶
Execute 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.
func (*Client[C, Q, M, R]) MessagesRaw ¶ added in v0.8.0
MessagesRaw returns the raw messages from the server. These are not connected to the request-response flow, typically used for log messages etc.
type ClientOptions ¶
type ClientOptions[C, Q, M, R any] struct { ClientRawOptions // The configuration to pass to the server. Config C // The codec to use. Codec codecs.Codec }
ClientOptions are options for the client.
type ClientRaw ¶
type ClientRaw struct { // Messages from the server that are not part of the request-response flow. Messages chan Message // 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.
func (*ClientRaw) Close ¶
Close closes the server connection and waits for the server process to quit.
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 // The timeout for the client. Timeout time.Duration }
ClientRawOptions are options for the raw part of the client.
type Dispatcher ¶
type Dispatcher interface { // SendMessage sends one or more message back to the client. SendMessage(...Message) }
Dispatcher is the interface for dispatching messages to the client.
type Header ¶
Header is the header of a message. ID and Size are set by the system. Status may be set by the system.
type Identity ¶ added in v0.8.0
type Identity struct { LastModified int64 `json:"lastModified"` ETag string `json:"eTag"` Size uint32 `json:"size"` }
Identity holds the modified time (Unix seconds) and a 64-bit checksum.
func (Identity) GetELastModified ¶ added in v0.8.0
GetELastModified returns the last modified time.
func (*Identity) SetELastModified ¶ added in v0.8.0
SetELastModified sets the last modified time.
type LastModifiedProvider ¶ added in v0.8.0
LastModifiedProvider is the interface for a type that can provide a last modified time.
type ProtocolInfo ¶ added in v0.10.0
type ProtocolInfo struct { // The version passed down from the client. // This usually represents a major version, // so any increment should be considered a breaking change. Version uint16 `json:"version"` }
ProtocolInfo is the protocol information passed to the server's Init function.
type Result ¶ added in v0.8.0
type Result[M, R any] struct { // contains filtered or unexported fields }
Result is the result of a request with zero or more messages and the receipt.
type Server ¶
Server is a stringly typed server for requests of type Q and responses of tye R.
type ServerOptions ¶
type ServerOptions[C, Q, M, R any] struct { // Init is the function that will be called when the server is started. // It can be used to initialize the server with the given configuration. // If an error is returned, the server will stop. Init func(C, ProtocolInfo) error // Handle is the function that will be called when a request is received. Handle func(*Call[Q, M, R]) // Codec is the codec that will be used to encode and decode requests, messages and receipts. // The client will tell the server what codec is in use, so in most cases you should just leave this unset. Codec codecs.Codec // GetHasher returns the hash instance to be used for the response body // If it's not set or it returns nil, no hash will be calculated. GetHasher func() hash.Hash // Delay delivery of messages to the client until Close is called. // Close takes a drop parameter that will drop any buffered messages. // This can be useful if you want to check the server generated ETag, // maybe the client already has this data. DelayDelivery bool }
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. // Message passed to the Dispatcher as part of the request/response must // use the same ID as the request. // ID 0 is reserved for standalone messages (e.g. log messages). Call func(Message, Dispatcher) error }
ServerRawOptions is the options for a raw portion of the server.
type SizeProvider ¶ added in v0.8.0
SizeProvider is the interface for a type that can provide a size.
type TagProvider ¶ added in v0.8.0
TagProvider is the interface for a type that can provide a eTag.
Directories
¶
Path | Synopsis |
---|---|
examples
|
|
servers/raw
Module
|
|
servers/readmeexample
Module
|
|
servers/typed
Module
|