Documentation
¶
Index ¶
- Variables
- type Attachment
- type AuthInterceptor
- type Client
- func (c *Client) Activate(ctx context.Context) error
- func (c *Client) Attach(ctx context.Context, doc *document.Document) error
- func (c *Client) Close() error
- func (c *Client) Deactivate(ctx context.Context) error
- func (c *Client) Detach(ctx context.Context, doc *document.Document) error
- func (c *Client) Dial(rpcAddr string) error
- func (c *Client) ID() *time.ActorID
- func (c *Client) IsActive() bool
- func (c *Client) Key() string
- func (c *Client) PeersMapByDoc() map[string]map[string]types.Presence
- func (c *Client) Presence() types.Presence
- func (c *Client) Sync(ctx context.Context, keys ...key.Key) error
- func (c *Client) UpdatePresence(ctx context.Context, k, v string) error
- func (c *Client) Watch(ctx context.Context, docs ...*document.Document) (<-chan WatchResponse, error)
- type Option
- func WithAPIKey(apiKey string) Option
- func WithCertFile(certFile string) Option
- func WithKey(key string) Option
- func WithLogger(logger *zap.Logger) Option
- func WithPresence(presence types.Presence) Option
- func WithServerNameOverride(serverNameOverride string) Option
- func WithToken(token string) Option
- type Options
- type WatchResponse
- type WatchResponseType
Constants ¶
This section is empty.
Variables ¶
var ( // ErrClientNotActivated occurs when an inactive client executes a function // that can only be executed when activated. ErrClientNotActivated = errors.New("client is not activated") // ErrDocumentNotAttached occurs when the given document is not attached to // this client. ErrDocumentNotAttached = errors.New("document is not attached") // ErrUnsupportedWatchResponseType occurs when the given WatchResponseType // is not supported. ErrUnsupportedWatchResponseType = errors.New("unsupported watch response type") )
Functions ¶
This section is empty.
Types ¶
type Attachment ¶ added in v0.1.6
type Attachment struct {
// contains filtered or unexported fields
}
Attachment represents the document attached and peers.
type AuthInterceptor ¶ added in v0.1.5
type AuthInterceptor struct {
// contains filtered or unexported fields
}
AuthInterceptor is an interceptor for authentication.
func NewAuthInterceptor ¶ added in v0.1.5
func NewAuthInterceptor(apiKey, token string) *AuthInterceptor
NewAuthInterceptor creates a new instance of AuthInterceptor.
func (*AuthInterceptor) Stream ¶ added in v0.1.5
func (i *AuthInterceptor) Stream() grpc.StreamClientInterceptor
Stream creates a stream server interceptor for authorization.
func (*AuthInterceptor) Unary ¶ added in v0.1.5
func (i *AuthInterceptor) Unary() grpc.UnaryClientInterceptor
Unary creates a unary server interceptor for authorization.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a normal client that can communicate with the server. It has documents and sends changes of the document in local to the server to synchronize with other replicas in remote.
func (*Client) Activate ¶
Activate activates this client. That is, it registers itself to the server and receives a unique ID from the server. The given ID is used to distinguish different clients.
func (*Client) Attach ¶
Attach attaches the given document to this client. It tells the server that this client will synchronize the given document.
func (*Client) Deactivate ¶
Deactivate deactivates this client.
func (*Client) Detach ¶
Detach detaches the given document from this client. It tells the server that this client will no longer synchronize the given document.
To collect garbage things like CRDT tombstones left on the document, all the changes should be applied to other replicas before GC time. For this, if the document is no longer used by this client, it should be detached.
func (*Client) PeersMapByDoc ¶ added in v0.1.6
PeersMapByDoc returns the peersMap.
func (*Client) Sync ¶
Sync pushes local changes of the attached documents to the server and receives changes of the remote replica from the server then apply them to local documents.
func (*Client) UpdatePresence ¶ added in v0.2.4
UpdatePresence updates the presence of this client.
func (*Client) Watch ¶
func (c *Client) Watch( ctx context.Context, docs ...*document.Document, ) (<-chan WatchResponse, error)
Watch subscribes to events on a given document. If an error occurs before stream initialization, the second response, error, is returned. If the context "ctx" is canceled or timed out, returned channel is closed, and "WatchResponse" from this closed channel has zero events and nil "Err()".
type Option ¶
type Option func(*Options)
Option configures Options.
func WithAPIKey ¶ added in v0.2.4
WithAPIKey configures the API key of the client.
func WithCertFile ¶ added in v0.2.1
WithCertFile configures the certificate file of the client.
func WithLogger ¶ added in v0.2.1
WithLogger configures the Logger of the client.
func WithPresence ¶ added in v0.2.4
WithPresence configures the presence of the client.
func WithServerNameOverride ¶ added in v0.2.1
WithServerNameOverride configures the server name override of the client.
type Options ¶ added in v0.2.1
type Options struct { // Key is the key of the client. It is used to identify the client. Key string // Presence is the presence of the client. Presence types.Presence // APIKey is the API key of the client. APIKey string // Token is the token of the client. Each request will be authenticated with this token. Token string // CertFile is the path to the certificate file. CertFile string // ServerNameOverride is the server name override. ServerNameOverride string // Logger is the Logger of the client. Logger *zap.Logger }
Options configures how we set up the client.
type WatchResponse ¶
type WatchResponse struct { Type WatchResponseType Keys []key.Key PeersMapByDoc map[string]map[string]types.Presence Err error }
WatchResponse is a structure representing response of Watch.
type WatchResponseType ¶ added in v0.1.6
type WatchResponseType string
WatchResponseType is type of watch response.
const ( DocumentsChanged WatchResponseType = "documents-changed" PeersChanged WatchResponseType = "peers-changed" )
The values below are types of WatchResponseType.