client

package
v0.4.18 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 23, 2024 License: Apache-2.0 Imports: 25 Imported by: 3

Documentation

Overview

Package client provides the client implementation of Yorkie. It is used to connect to the server and attach documents.

Index

Constants

This section is empty.

Variables

View Source
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")

	// ErrDocumentNotDetached occurs when the given document is not detached from
	// this client.
	ErrDocumentNotDetached = errors.New("document is not detached")

	// ErrUnsupportedWatchResponseType occurs when the given WatchResponseType
	// is not supported.
	ErrUnsupportedWatchResponseType = errors.New("unsupported watch response type")

	// ErrInitializationNotReceived occurs when the first response of the watch stream is not received.
	ErrInitializationNotReceived = errors.New("initialization is not received")

	// ErrAlreadySubscribed occurs when the client is already subscribed to the document.
	ErrAlreadySubscribed = errors.New("already subscribed")
)

Functions

This section is empty.

Types

type AttachOption added in v0.4.5

type AttachOption func(*AttachOptions)

AttachOption configures AttachOptions.

func WithPresence added in v0.2.4

func WithPresence(presence innerpresence.Presence) AttachOption

WithPresence configures the presence of the client.

type AttachOptions added in v0.4.5

type AttachOptions struct {
	// Presence is the presence of the client.
	Presence innerpresence.Presence
}

AttachOptions configures how we set up the document.

type Attachment added in v0.1.6

type Attachment struct {
	// contains filtered or unexported fields
}

Attachment represents the document attached.

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) WrapStreamingClient added in v0.4.11

WrapStreamingClient creates a stream client interceptor for authorization.

func (*AuthInterceptor) WrapStreamingHandler added in v0.4.11

WrapStreamingHandler creates a stream server interceptor for authorization.

func (*AuthInterceptor) WrapUnary added in v0.4.11

func (i *AuthInterceptor) WrapUnary(next connect.UnaryFunc) connect.UnaryFunc

WrapUnary 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 Dial added in v0.1.2

func Dial(rpcAddr string, opts ...Option) (*Client, error)

Dial creates an instance of Client and dials the given rpcAddr.

func New added in v0.2.1

func New(opts ...Option) (*Client, error)

New creates an instance of Client.

func (*Client) Activate

func (c *Client) Activate(ctx context.Context) error

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

func (c *Client) Attach(ctx context.Context, doc *document.Document, options ...AttachOption) error

Attach attaches the given document to this client. It tells the server that this client will synchronize the given document.

func (*Client) Close

func (c *Client) Close() error

Close closes all resources of this client.

func (*Client) Deactivate

func (c *Client) Deactivate(ctx context.Context) error

Deactivate deactivates this client.

func (*Client) Detach

func (c *Client) Detach(ctx context.Context, doc *document.Document, options ...DetachOption) error

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) Dial added in v0.1.2

func (c *Client) Dial(rpcAddr string) error

Dial dials the given rpcAddr.

func (*Client) ID added in v0.1.6

func (c *Client) ID() *time.ActorID

ID returns the ID of this client.

func (*Client) IsActive

func (c *Client) IsActive() bool

IsActive returns whether this client is active or not.

func (*Client) Key added in v0.1.6

func (c *Client) Key() string

Key returns the key of this client.

func (*Client) Remove added in v0.3.3

func (c *Client) Remove(ctx context.Context, doc *document.Document) error

Remove removes the given document.

func (*Client) Subscribe added in v0.4.17

func (c *Client) Subscribe(
	doc *document.Document,
) (<-chan WatchResponse, context.CancelFunc, error)

Subscribe subscribes to events on a given document.

func (*Client) Sync

func (c *Client) Sync(ctx context.Context, options ...SyncOptions) error

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.

type DetachOption added in v0.4.5

type DetachOption func(*DetachOptions)

DetachOption configures DetachOptions.

func WithRemoveIfNotAttached added in v0.4.5

func WithRemoveIfNotAttached() DetachOption

WithRemoveIfNotAttached configures the removeIfNotAttached of the document.

type DetachOptions added in v0.4.5

type DetachOptions struct {
	// contains filtered or unexported fields
}

DetachOptions configures how we set up the document.

type Option

type Option func(*Options)

Option configures Options.

func WithAPIKey added in v0.2.4

func WithAPIKey(apiKey string) Option

WithAPIKey configures the API key of the client.

func WithCertFile added in v0.2.1

func WithCertFile(certFile string) Option

WithCertFile configures the certificate file of the client.

func WithKey added in v0.2.1

func WithKey(key string) Option

WithKey configures the key of the client.

func WithLogger added in v0.2.1

func WithLogger(logger *zap.Logger) Option

WithLogger configures the Logger of the client.

func WithMaxRecvMsgSize added in v0.2.10

func WithMaxRecvMsgSize(maxRecvMsgSize int) Option

WithMaxRecvMsgSize configures the maximum message size in bytes the client can receive.

func WithServerNameOverride added in v0.2.1

func WithServerNameOverride(serverNameOverride string) Option

WithServerNameOverride configures the server name override of the client.

func WithToken added in v0.2.1

func WithToken(token string) Option

WithToken configures the token 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

	// 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

	// MaxCallRecvMsgSize is the maximum message size in bytes the client can receive.
	MaxCallRecvMsgSize int
}

Options configures how we set up the client.

type SyncOptions added in v0.4.5

type SyncOptions struct {
	// contains filtered or unexported fields
}

SyncOptions is an option for sync. It contains the key of the document to sync and the sync mode.

func WithDocKey added in v0.3.4

func WithDocKey(k key.Key) SyncOptions

WithDocKey creates a SyncOptions with the given document key.

func (SyncOptions) WithPushOnly added in v0.4.5

func (o SyncOptions) WithPushOnly() SyncOptions

WithPushOnly returns a SyncOptions with the sync mode set to PushOnly.

type WatchResponse

type WatchResponse struct {
	Type      WatchResponseType
	Presences map[string]innerpresence.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 (
	DocumentChanged   WatchResponseType = "document-changed"
	DocumentWatched   WatchResponseType = "document-watched"
	DocumentUnwatched WatchResponseType = "document-unwatched"
	PresenceChanged   WatchResponseType = "presence-changed"
	DocumentBroadcast WatchResponseType = "document-broadcast"
)

The values below are types of WatchResponseType.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL