syncer

package
v3.5.1 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Unchanged = 0
	Insert    = 1
	Update    = 2
	Delete    = 3
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Syncer

type Syncer[T any, V comparable] struct {
	// contains filtered or unexported fields
}

Syncer is a struct that holds functions for synchronizing data. It includes functions for inserting, updating, deleting, and notifying, as well as functions for generating unique IDs and checking equality of data items.

func New

func New[T any, V comparable](
	insert func(ctx context.Context, value T) error,
	delete func(ctx context.Context, value T) error,
	update func(ctx context.Context, server T, local T) error,
	uuid func(value T) V,
	equal func(a T, b T) bool,
	notice func(ctx context.Context, state int, server, local T) error,
) *Syncer[T, V]

New creates a new Syncer instance with the provided synchronization functions. This function requires several callback functions to handle different aspects of data synchronization: - insert: A function to insert new data. - delete: A function to delete existing data. - update: A function to update existing data. - uuid: A function to generate a unique identifier for each data item. - equal: A function to check if two data items are equal. - notice: A function to handle notifications during the sync process. Panics if insert, delete, update, or uuid functions are not provided.

func (*Syncer[T, V]) Sync

func (s *Syncer[T, V]) Sync(ctx context.Context, serverData []T, localData []T, notice func(ctx context.Context, state int, server, local T) error, noDel ...bool) (err error)

Sync synchronizes server data with local data. Sync synchronizes the data between the server and local storage. It takes a context, two slices of data (serverData and localData), a notice function to handle notifications during the sync process, and a variadic parameter noDel to control deletion behavior.

Jump to

Keyboard shortcuts

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