Documentation
¶
Index ¶
- Constants
- func CompareHeads(a []automerge.ChangeHash, b []automerge.ChangeHash) (missingInA int, missingInB int)
- func HasAllRemoteHeads(doc *automerge.Doc, m *automerge.SyncMessage) bool
- func HeadsEqualCheck(doc *automerge.Doc, m *automerge.SyncMessage) bool
- func Logger(ctx context.Context) *slog.Logger
- func NoReadPredicate(doc *automerge.Doc, msg *automerge.SyncMessage) (bool, error)
- func NoTerminationCheck(doc *automerge.Doc, m *automerge.SyncMessage) bool
- func SetContextLogger(ctx context.Context, l *slog.Logger) context.Context
- func SkipChangesReadPredicate(doc *automerge.Doc, msg *automerge.SyncMessage) (bool, error)
- type ClientOption
- type HttpDoer
- type HttpDoerFunc
- type LoggableChangeHashes
- type NdJson
- type ReadPredicate
- type ServerOption
- type SharedDoc
- func (b *SharedDoc) Doc() *automerge.Doc
- func (b *SharedDoc) HttpPushPullChanges(ctx context.Context, url string, opts ...ClientOption) error
- func (b *SharedDoc) NotifyReceivedChanges()
- func (b *SharedDoc) ServeChanges(rw http.ResponseWriter, req *http.Request, opts ...ServerOption) (finalErr error)
- func (b *SharedDoc) SubscribeToReceivedChanges() (chan bool, func())
- type TerminationCheck
Constants ¶
const ContentType = "application/x-ndjson"
const ContentTypeWithCharset = ContentType + "; charset=utf-8"
const EventSync = "sync"
Variables ¶
This section is empty.
Functions ¶
func CompareHeads ¶
func CompareHeads(a []automerge.ChangeHash, b []automerge.ChangeHash) (missingInA int, missingInB int)
CompareHeads is a utility function that compares change hash arrays and returns values indicating the intersection or overlap.
func HasAllRemoteHeads ¶
func HasAllRemoteHeads(doc *automerge.Doc, m *automerge.SyncMessage) bool
HasAllRemoteHeads will continue accepting messages until it confirms that the local doc contains all the remote heads. But the opposite may not be true.
func HeadsEqualCheck ¶
func HeadsEqualCheck(doc *automerge.Doc, m *automerge.SyncMessage) bool
HeadsEqualCheck will continue accepting messages until both the local doc and remote doc have the same heads.
func NoReadPredicate ¶ added in v1.2.0
NoReadPredicate is a ReadPredicate which includes all messages
func NoTerminationCheck ¶
func NoTerminationCheck(doc *automerge.Doc, m *automerge.SyncMessage) bool
NoTerminationCheck will continue reading all messages and not stop.
func SetContextLogger ¶ added in v1.3.0
func SkipChangesReadPredicate ¶ added in v1.2.0
SkipChangesReadPredicate is a ReadPredicate which skips any messages that contain changes. Effectively turning the doc read only since it does not accept incoming changes but is happy to doll them out.
Types ¶
type ClientOption ¶
type ClientOption func(*clientOptions)
func WithClientRequestEditor ¶
func WithClientRequestEditor(f func(r *http.Request)) ClientOption
func WithClientSyncState ¶
func WithClientSyncState(state *automerge.SyncState) ClientOption
func WithClientTerminationCheck ¶
func WithClientTerminationCheck(check TerminationCheck) ClientOption
func WithHttpClient ¶
func WithHttpClient(client HttpDoer) ClientOption
type HttpDoerFunc ¶
type LoggableChangeHashes ¶
type LoggableChangeHashes []automerge.ChangeHash
LoggableChangeHashes is a type alias that allows the change hash array that represents the document heads to be easily attached to log messages via the slog.LogValuer interface.
func (LoggableChangeHashes) LogValue ¶
func (l LoggableChangeHashes) LogValue() slog.Value
type ReadPredicate ¶ added in v1.2.0
A ReadPredicate is used to filter messages before receiving them in the doc. The function should return a bool (true=include, false=exclude/skip). An error will cause the sync to abort.
type ServerOption ¶
type ServerOption func(*serverOptions)
func WithReadPredicate ¶ added in v1.2.0
func WithReadPredicate(f ReadPredicate) ServerOption
func WithServerHeaderEditor ¶
func WithServerHeaderEditor(f func(headers http.Header)) ServerOption
func WithServerSyncState ¶
func WithServerSyncState(state *automerge.SyncState) ServerOption
func WithTerminationCheck ¶ added in v1.2.0
func WithTerminationCheck(f TerminationCheck) ServerOption
type SharedDoc ¶
type SharedDoc struct {
// contains filtered or unexported fields
}
SharedDoc encapsulates a doc with a signalling mechanism that broadcasts an event when new messages changes have been synced into the doc. This event is generally used to wake up other goroutines for generating sync messages to other clients or servers but can also be used to driver other mechanisms like backups or transformers.
func NewSharedDoc ¶
func NewSharedDoc(doc *automerge.Doc) *SharedDoc
NewSharedDoc returns a new SharedDoc
func (*SharedDoc) Doc ¶
func (b *SharedDoc) Doc() *automerge.Doc
Doc returns the document held by this SharedDoc.
func (*SharedDoc) HttpPushPullChanges ¶
func (b *SharedDoc) HttpPushPullChanges(ctx context.Context, url string, opts ...ClientOption) error
HttpPushPullChanges is the HTTP client function to synchronise a local document with a remote server. This uses either HTTP2 or HTTP1.1 depending on the remote server - HTTP2 is preferred since it has better understood bidirectional body capabilities.
func (*SharedDoc) NotifyReceivedChanges ¶
func (b *SharedDoc) NotifyReceivedChanges()
NotifyReceivedChanges should be called after the shared doc has "received" a message. This allows any goroutines that are generating messages to be preempted and know that new messaged may be available. This is a broadcast because any number of goroutines may be writing changes to the doc to their client.
func (*SharedDoc) ServeChanges ¶
func (b *SharedDoc) ServeChanges(rw http.ResponseWriter, req *http.Request, opts ...ServerOption) (finalErr error)
func (*SharedDoc) SubscribeToReceivedChanges ¶ added in v1.2.0
SubscribeToReceivedChanges allows the caller to subscribe to changes received by the doc. Call the finish function to clean up.
type TerminationCheck ¶
type TerminationCheck func(doc *automerge.Doc, m *automerge.SyncMessage) bool
TerminationCheck can be used on a message reader to stop reading messages when the local document and remote document are suitably in-sync. NoTerminationCheck will never stop reading.