execrpc package - github.com/bep/execrpc - Go Packages

View Source

const (
	
	MessageStatusOK = iota

	
	MessageStatusContinue

	
	MessageStatusInitServer

	
	MessageStatusErrDecodeFailed
	
	MessageStatusErrEncodeFailed
	
	MessageStatusErrInitServerFailed

	
	MessageStatusSystemReservedMax = 99
)

View Source

var (
	
	ErrTimeoutWaitingForServer = errors.New("timed out waiting for server to start")
	
	ErrTimeoutWaitingForCall = errors.New("timed out waiting for call to complete")
)

ErrShutdown will be returned from Execute and Close if the client is or is about to be shut down.

This section is empty.

type Call[Q, M, R any] struct {
	Request Q
	
}

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 (c *Call[Q, M, R]) Close(drop bool, r R)

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.

func (c *Call[Q, M, R]) Enqueue(rr ...M)

Enqueue enqueues one or more messages to be sent back to the client.

func (c *Call[Q, M, R]) Receipt() <-chan R
func (c *Call[Q, M, R]) SendRaw(ms ...Message)

SendRaw sends one or more messages back to the client that is not part of the request/response exchange. These messages must have ID 0.

type Client[C, Q, M, R any] struct {
	
}

Client is a strongly typed RPC client.

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 (c *Client[C, Q, M, R]) Close() error

Close closes the client.

func (c *Client[C, Q, M, R]) Execute(r Q) Result[M, R]

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 (c *Client[C, Q, M, R]) MessagesRaw() <-chan Message

MessagesRaw returns the raw messages from the server. These are not connected to the request-response flow, typically used for log messages etc.

ClientOptions are options for the client.

type ClientRaw struct {

	
	Messages chan Message
	
}

ClientRaw is a raw RPC client. Raw means that the client doesn't do any type conversion, a byte slice is what you get.

StartClientRaw starts a untyped client client for the given options.

Close closes the server connection and waits for the server process to quit.

func (c *ClientRaw) Execute(withMessage func(m *Message), messages chan<- Message) error

Execute 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.

ClientRawOptions are options for the raw part of the client.

type Dispatcher interface {
	
	SendMessage(...Message)
}

Dispatcher is the interface for dispatching messages to the client.

Header is the header of a message. ID and Size are set by the system. Status may be set by the system.

Read reads the header from the reader.

Write writes the header to the writer.

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 (i Identity) GetELastModified() int64

GetELastModified returns the last modified time.

GetESize returns the size.

GetETag returns the checksum.

func (i *Identity) SetELastModified(t int64)

SetELastModified sets the last modified time.

SetETag sets the checksum.

type LastModifiedProvider interface {
	GetELastModified() int64
	SetELastModified(int64)
}

LastModifiedProvider is the interface for a type that can provide a last modified time.

type Message struct {
	Body   []byte
}

Message is what gets sent to and from the server.

type ProtocolInfo struct {
	
	
	
	Version uint16 `json:"version"`
}

ProtocolInfo is the protocol information passed to the server's Init function.

type Result[M, R any] struct {
	
}

Result is the result of a request with zero or more messages and the receipt.

func (r Result[M, R]) Messages() <-chan M

Messages returns the messages from the server.

func (r Result[M, R]) Receipt() <-chan R

Receipt returns the receipt from the server.

type Server[C, Q, M, R any] struct {
	*ServerRaw
	
}

Server is a stringly typed server for requests of type Q and responses of tye R.

func NewServer[C, Q, M, R any](opts ServerOptions[C, Q, M, R]) (*Server[C, Q, M, R], error)

NewServer creates a new Server. using the given options.

func (s *Server[C, Q, M, R]) Start() error

ServerOptions is the options for a server.

type ServerRaw struct {
	
}

ServerRaw is a RPC server handling raw messages with a header and []byte body. See Server for a generic, typed version.

NewServerRaw creates a new Server using the given options.

Start sets upt the server communication and starts the server loop.

type ServerRawOptions struct {
	
	
	
	
	
	
	Call func(Message, Dispatcher) error
}

ServerRawOptions is the options for a raw portion of the server.

type SizeProvider interface {
	GetESize() uint32
	SetESize(uint32)
}

SizeProvider is the interface for a type that can provide a size.

type TagProvider interface {
	GetETag() string
	SetETag(string)
}

TagProvider is the interface for a type that can provide a eTag.