syncer

package
v3.8.1-rc.3 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2024 License: Apache-2.0 Imports: 8 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 NoResp added in v3.8.0

type NoResp struct{}

type Option added in v3.8.0

type Option[T, RESP any, V comparable] func(*Syncer[T, RESP, V])

Option is a function that configures a Syncer.

func WithBatchInsert added in v3.8.0

func WithBatchInsert[T, RESP any, V comparable](f func(ctx context.Context, values []T) error) Option[T, RESP, V]

WithBatchInsert sets the batchInsert function for the Syncer.

func WithBatchPageReq added in v3.8.0

func WithBatchPageReq[T, RESP any, V comparable](f func(entityID string) page.PageReq) Option[T, RESP, V]

WithBatchPageReq sets the batchPageReq for the Syncer.

func WithBatchPageRespConvertFunc added in v3.8.0

func WithBatchPageRespConvertFunc[T, RESP any, V comparable](f func(resp *RESP) []T) Option[T, RESP, V]

WithBatchPageRespConvertFunc sets the batchPageRespConvertFunc function for the Syncer.

func WithDelete added in v3.8.0

func WithDelete[T, RESP any, V comparable](f func(ctx context.Context, local T) error) Option[T, RESP, V]

WithDelete sets the delete function for the Syncer.

func WithDeleteAll added in v3.8.0

func WithDeleteAll[T, RESP any, V comparable](f func(ctx context.Context, entityID string) error) Option[T, RESP, V]

WithDeleteAll sets the deleteAll function for the Syncer.

func WithEqual added in v3.8.0

func WithEqual[T, RESP any, V comparable](f func(a T, b T) bool) Option[T, RESP, V]

WithEqual sets the equal function for the Syncer.

func WithFullSyncLimit added in v3.8.0

func WithFullSyncLimit[T, RESP any, V comparable](limit int64) Option[T, RESP, V]

WithFullSyncLimit sets the fullSyncLimit for the Syncer.

func WithInsert added in v3.8.0

func WithInsert[T, RESP any, V comparable](f func(ctx context.Context, value T) error) Option[T, RESP, V]

WithInsert sets the insert function for the Syncer.

func WithNotice added in v3.8.0

func WithNotice[T, RESP any, V comparable](f func(ctx context.Context, state int, server, local T) error) Option[T, RESP, V]

WithNotice sets the notice function for the Syncer.

func WithReqApiRouter added in v3.8.0

func WithReqApiRouter[T, RESP any, V comparable](router string) Option[T, RESP, V]

WithReqApiRouter sets the reqApiRouter for the Syncer.

func WithUUID added in v3.8.0

func WithUUID[T, RESP any, V comparable](f func(value T) V) Option[T, RESP, V]

WithUUID sets the uuid function for the Syncer.

func WithUpdate added in v3.8.0

func WithUpdate[T, RESP any, V comparable](f func(ctx context.Context, server T, local T) error) Option[T, RESP, V]

WithUpdate sets the update function for the Syncer.

type Syncer

type Syncer[T, RESP 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, RESP 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, RESP, 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 New2 added in v3.8.0

func New2[T, RESP any, V comparable](opts ...Option[T, RESP, V]) *Syncer[T, RESP, V]

func NewSyncer added in v3.8.0

func NewSyncer[T, RESP any, V comparable](opts ...Option[T, RESP, V]) *Syncer[T, RESP, V]

NewSyncer creates a new Syncer with the provided options.

func (*Syncer[T, RESP, V]) FullSync added in v3.8.0

func (s *Syncer[T, RESP, V]) FullSync(ctx context.Context, entityID string) (err error)

func (*Syncer[T, RESP, V]) Sync

func (s *Syncer[T, RESP, V]) Sync(ctx context.Context, serverData []T, localData []T, notice func(ctx context.Context, state int, server, local T) error, skipDeletionAndNotice ...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 skipDeletion to control deletion behavior.

Jump to

Keyboard shortcuts

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