Documentation
¶
Index ¶
Examples ¶
Constants ¶
const ( // AddOnly only runs add operations. AddOnly OperatingMode = "Add" // RemoveOnly only runs remove operations. RemoveOnly OperatingMode = "Remove" // RemoveAdd first removes things, then adds them. RemoveAdd OperatingMode = "RemoveAdd" // AddRemove first adds things, then removes them. AddRemove OperatingMode = "AddRemove" // NoChangeLimit tells Sync not to set a change limit. NoChangeLimit int = -1 )
Variables ¶
var ErrCacheEmpty = errors.New("cache is empty, run Get first")
ErrCacheEmpty is returned if an adapter expects Get to be called before Add/Remove.
var ErrInvalidConfig = errors.New("invalid configuration")
ErrInvalidConfig is returned when an InitFn is passed an invalid configuration.
var ErrMissingConfig = errors.New("missing configuration")
ErrMissingConfig is returned when an InitFn is missing a required configuration.
var ErrNotImplemented = errors.New("not implemented")
ErrNotImplemented is for brand-new adapters that are still being worked on.
var ErrReadOnly = errors.New("cannot perform action, adapter is readonly")
ErrReadOnly is returned for adapters that cannot Add/Remove, but have been set as a destination.
var ErrTooManyChanges = errors.New("too many changes")
ErrTooManyChanges is returned when a change limit has been set, and the number of changes exceeds it.
Functions ¶
func SetCaseSensitive ¶
SetCaseSensitive can configure Go Sync's case sensitivity when comparing things.
Example ¶
package main
import (
"github.com/ovotech/go-sync/packages/gosync"
)
func main() {
// Any Go Sync adapter.
var source gosync.Adapter
gosync.New(source, gosync.SetCaseSensitive(true))
}
Output:
func SetMaximumChanges ¶
SetMaximumChanges sets a maximum number of changes that Sync will allow before returning an ErrTooManyChanges error.
Example ¶
package main
import (
"github.com/ovotech/go-sync/packages/gosync"
)
func main() {
// Any Go Sync adapter.
var source gosync.Adapter
gosync.New(source, gosync.SetMaximumChanges(5))
}
Output:
func SetOperatingMode ¶
func SetOperatingMode(mode OperatingMode) func(*Sync)
SetOperatingMode sets a custom operating mode.
Example ¶
package main
import (
"github.com/ovotech/go-sync/packages/gosync"
)
func main() {
// Any Go Sync adapter.
var source gosync.Adapter
// Set the operating mode to add only (don't remove things).
operatingMode := gosync.SetOperatingMode(gosync.AddOnly)
gosync.New(source, operatingMode)
}
Output:
Types ¶
type Adapter ¶
type Adapter interface {
Get(ctx context.Context) (things []string, err error) // Get things in a service.
Add(ctx context.Context, things []string) error // Add things to a service.
Remove(ctx context.Context, things []string) error // Remove things from a service.
}
Adapter interfaces are used to allow Sync to communicate with third party services.
type InitFn ¶
InitFn is an optional adapter function that can initialise a new adapter using a static configuration. This is to make it easier to use an adapter in a CLI or other service that invokes adapters programmatically.
type OperatingMode ¶
type OperatingMode string
OperatingMode specifies how Sync operates, which sync operations are run and in what order.
type Service ¶
type Service interface {
SyncWith(ctx context.Context, adapter Adapter) error // Sync the things in a source service with this service.
}
Service can be used for downstream services that implement Sync in your own workflow.
type Sync ¶
type Sync struct {
DryRun bool // DryRun mode calculates membership, but doesn't add or remove.
// contains filtered or unexported fields
}
func New ¶
New creates a new gosync.Sync service.
Example ¶
package main
import (
"github.com/ovotech/go-sync/packages/gosync"
)
func main() {
// Any Go Sync adapter.
var source gosync.Adapter
gosync.New(source)
}
Output:
func (*Sync) SyncWith ¶
SyncWith synchronises the destination service with the source service, adding & removing things as necessary.
Example ¶
package main
import (
"context"
"log"
"github.com/ovotech/go-sync/packages/gosync"
)
func main() {
// Any Go Sync adapters.
var source, destination gosync.Adapter
sync := gosync.New(source)
// By default, Go Sync runs in dry run mode. To make changes this must manually be set to false.
sync.DryRun = false
err := sync.SyncWith(context.Background(), destination)
if err != nil {
log.Panic(err)
}
}
Output: