La référence API provient des commentaires de documentation Go du code source et est rédigée en anglais.
package liveops
import "github.com/nsgo-dev/game/pkg/liveops"Vue d’ensemble
Package liveops holds provider-agnostic live operations primitives for NSGo games: crash reports, consent-gated analytics, a cloud-save sync interface and in-app purchases credited into the save. It links no third-party analytics, crash-reporting, ad or payment SDKs.
Scope (#194)
In scope for the core game module:
- Crash reports (#195): panic recovery around game.Loop and arbitrary callbacks, with a fixed-size step ring buffer, stack trace, metadata and an optional state snapshot handed to the app's reporter.
- Analytics (#198): a provider-agnostic, strictly opt-in event API whose consent state persists in core.Storage. Zero events are sent or buffered before explicit ConsentGranted.
- Cloud saves (#196): the provider-agnostic CloudSync interface, PlatformCloud over NSGo's cloud package (iCloud on macOS/iOS, Google Play Games Saved Games on Android, and the in-memory store in nsgotest), DirCloud for Steam Auto-Cloud and other directory-synced stores, CloudClient (#557) for the self-hosted cloudsave service, and CloudSyncer (#539), which detects slots changed on two devices and resolves them by policy without silently losing either copy.
- In-app purchases (#369): Purchases over NSGo's purchase services, which credits consumables into the save exactly once through a Ledger saved with them, keeps unlocks and subscriptions from the store's entitlements, restores them, follows purchases waiting for approval and hands transactions to an optional server before delivering them.
Out of scope for the core game module:
- Ads (#199): ad networks (AdMob, AppLovin and similar) require proprietary native SDKs with store-policy and privacy obligations that do not belong in the core game layer. Games that show ads embed native SDK views directly through NSGo.
Index
- Constantes
- Variables
- func EncodeCloudSave(v SaveVersion) ([]byte, error)
- func PayloadHash(payload []byte) string
- type Analytics
- func NewAnalytics(store core.Storage, key string, provider AnalyticsProvider) *Analytics
- func NewMemoryAnalytics(provider AnalyticsProvider) *Analytics
- func (a *Analytics) Consent() ConsentState
- func (a *Analytics) Flush() error
- func (a *Analytics) SetClock(now func() time.Time)
- func (a *Analytics) SetConsent(state ConsentState) error
- func (a *Analytics) SetProvider(provider AnalyticsProvider)
- func (a *Analytics) Track(name string, props map[string]any) bool
- type AnalyticsProvider
- type BuyResult
- type Choice
- type CloudChange
- type CloudClient
- func NewCloudClient(opts CloudClientOptions) (*CloudClient, error)
- func (c *CloudClient) Delete(ctx context.Context, slot string) error
- func (c *CloudClient) DeleteIf(ctx context.Context, slot, match string) error
- func (c *CloudClient) List(ctx context.Context) ([]string, error)
- func (c *CloudClient) Load(ctx context.Context, slot string) ([]byte, error)
- func (c *CloudClient) LoadVersion(ctx context.Context, slot string, number int64) ([]byte, error)
- func (c *CloudClient) Purge(ctx context.Context, slot string) error
- func (c *CloudClient) Restore(ctx context.Context, slot string, number int64) error
- func (c *CloudClient) Save(ctx context.Context, slot string, data []byte) error
- func (c *CloudClient) SaveIf(ctx context.Context, slot string, data []byte, match string) error
- func (c *CloudClient) Versions(ctx context.Context, slot string) ([]CloudVersion, error)
- type CloudClientOptions
- type CloudProvider
- type CloudSync
- type CloudSyncOptions
- type CloudSyncer
- func NewCloudSyncer(opts CloudSyncOptions) (*CloudSyncer, error)
- func (s *CloudSyncer) Backend() save.Backend
- func (s *CloudSyncer) Resolve(ctx context.Context, c Conflict, choice Choice) (SlotResult, error)
- func (s *CloudSyncer) ResolveAsync(cx *core.Scope, ctx context.Context, c Conflict, choice Choice, done func(SlotResult, error))
- func (s *CloudSyncer) Sync(ctx context.Context) (SyncResult, error)
- func (s *CloudSyncer) SyncAsync(cx *core.Scope, ctx context.Context, done func(SyncResult, error))
- func (s *CloudSyncer) SyncSlot(ctx context.Context, slot string) (SlotResult, error)
- func (s *CloudSyncer) SyncSlotAsync(cx *core.Scope, ctx context.Context, slot string, done func(SlotResult, error))
- type CloudVersion
- type ConditionalCloudSync
- type Conflict
- type ConflictPolicy
- type ConsentState
- type CrashOptions
- type CrashReport
- type CrashReporter
- func NewCrashReporter(opts CrashOptions) *CrashReporter
- func (c *CrashReporter) DeleteMetadata(key string)
- func (c *CrashReporter) GuardLoop(l *game.Loop)
- func (c *CrashReporter) LastSteps() []StepRecord
- func (c *CrashReporter) RecordStep(dt time.Duration, summary string) uint64
- func (c *CrashReporter) RecordStepData(dt time.Duration, summary string, data any) uint64
- func (c *CrashReporter) Reset()
- func (c *CrashReporter) RunSafe(fn func()) (panicked bool)
- func (c *CrashReporter) SetMetadata(key, value string)
- func (c *CrashReporter) Step() uint64
- func (c *CrashReporter) WrapLoop(l *game.Loop) *game.Loop
- type DirCloud
- func NewDirCloud(dir string) (*DirCloud, error)
- func (c *DirCloud) Delete(ctx context.Context, slot string) error
- func (c *DirCloud) DeleteIf(ctx context.Context, slot, match string) error
- func (c *DirCloud) Dir() string
- func (c *DirCloud) List(ctx context.Context) ([]string, error)
- func (c *DirCloud) Load(ctx context.Context, slot string) ([]byte, error)
- func (c *DirCloud) Save(ctx context.Context, slot string, data []byte) error
- func (c *DirCloud) SaveIf(ctx context.Context, slot string, data []byte, match string) error
- type Event
- type Ledger
- type PlatformCloud
- func NewPlatformCloud(cx *core.Scope, opts PlatformCloudOptions) (*PlatformCloud, error)
- func (c *PlatformCloud) Available() bool
- func (c *PlatformCloud) Delete(ctx context.Context, slot string) error
- func (c *PlatformCloud) FileName(slot string) (string, error)
- func (c *PlatformCloud) List(ctx context.Context) ([]string, error)
- func (c *PlatformCloud) Load(ctx context.Context, slot string) ([]byte, error)
- func (c *PlatformCloud) OnConflict(resolve func(PlatformConflict)) (stop func())
- func (c *PlatformCloud) Prefix() string
- func (c *PlatformCloud) Provider() CloudProvider
- func (c *PlatformCloud) Save(ctx context.Context, slot string, data []byte) error
- func (c *PlatformCloud) WatchChanges(onChange func(CloudChange)) (stop func())
- type PlatformCloudOptions
- type PlatformConflict
- type Purchases
- func NewPurchases(cx *core.Scope, opts PurchasesOptions) *Purchases
- func (p *Purchases) Available() bool
- func (p *Purchases) Buy(product string, quantity int, done func(BuyResult, error))
- func (p *Purchases) Entitlement(product string) (core.Transaction, bool)
- func (p *Purchases) Owned(product string) bool
- func (p *Purchases) Pending(product string) bool
- func (p *Purchases) Refresh(done func(error))
- func (p *Purchases) Restore(done func(error))
- type PurchasesOptions
- type SaveVersion
- type SlotResult
- type StepRecord
- type SyncOutcome
- type SyncResult
Constantes
const CloudSaveFormat = "nsgo-cloud-save"CloudSaveFormat is the "format" value that marks a cloud payload written by CloudSyncer. A payload without it is read as a plain save written by a game that used CloudSync directly, at revision 0.
const CloudSaveVersion = 1CloudSaveVersion is the schema version of the cloud payload CloudSyncer writes and the newest one it reads.
const DefaultCloudPrefix = "save."DefaultCloudPrefix is the file-name prefix PlatformCloud prepends to each save slot when PlatformCloudOptions.Prefix is empty, storing slot "main" as "save.main.json". A flat dot-separated name without slashes works in both Apple iCloud ubiquity containers and Google Play Games Saved Games snapshots, and keeps save slots separate from other files in the container.
const DefaultConsentKey = "liveops.analytics.consent"DefaultConsentKey is the core.Storage key used by NewAnalytics when key is empty.
const DefaultHistorySize = 120DefaultHistorySize is the number of recent steps a CrashReporter keeps when CrashOptions.HistorySize is 0 or negative.
const DefaultSyncStateKey = "liveops.cloudsync"DefaultSyncStateKey is the core.Storage key prefix under which CloudSyncer keeps each slot's sync state when CloudSyncOptions.StateKey is empty.
const LedgerLimit = 1024LedgerLimit is how many transaction IDs each list of a Ledger keeps; the oldest are dropped past it to bound the save's size. A store hands a game only its unfinished transactions again, and a finished transaction is never far back in the list, so no credit repeats. A refund, though, can come weeks after its purchase: one whose ID has been dropped, after LedgerLimit newer consumables were credited, is finished without running Revoke.
Variables
var (
// ErrCorruptCloudSave reports a cloud payload marked with CloudSaveFormat that does not decode: an unknown field, a newer schema version, a hash that does not match its data, or a malformed value. The slot is left untouched on both sides.
ErrCorruptCloudSave = errors.New("liveops: corrupt cloud save")
// ErrCorruptSyncState reports a slot's stored sync state that does not decode. The slot is left untouched on both sides.
ErrCorruptSyncState = errors.New("liveops: corrupt cloud sync state")
// ErrCloudChanged reports that the cloud copy of a slot changed between CloudSyncer reading it and writing it, such as when another device uploaded at the same moment. Nothing was written; the next sync sees the new copy.
ErrCloudChanged = errors.New("liveops: cloud save changed during sync")
// ErrConflictChanged reports that a slot passed to CloudSyncer.Resolve no longer holds the copies of the Conflict it was given, because a save or a sync changed either side since. Nothing was written; sync again to see the current conflict, if any.
ErrConflictChanged = errors.New("liveops: save changed since the conflict was reported")
// ErrInvalidDevice reports a device ID that is empty, longer than 64 bytes or not made of ASCII letters, digits, '-' and '_'.
ErrInvalidDevice = errors.New("liveops: invalid device id")
)var ErrCloudConflict = errors.New("liveops: platform cloud save conflict")ErrCloudConflict is returned by PlatformCloud when the native cloud backend (iCloud NSFileVersion or Google Play Games Saved Games) holds unresolved conflicting versions of a slot. Resolve it through PlatformCloud.OnConflict or by writing the winning payload.
ErrCloudUnavailable is returned by a CloudSync implementation when cloud storage is signed out, offline or unsupported on the current target.
var ErrInvalidConsent = errors.New("liveops: invalid consent state")ErrInvalidConsent is returned by Analytics.SetConsent when given an unknown ConsentState value.
var ErrNoLedger = errors.New("liveops: purchases need a ledger")ErrNoLedger is what Buy and every delivery answer when PurchasesOptions has no Ledger to record credits in.
var ErrSlotNotFound = errors.New("liveops: cloud save slot not found")ErrSlotNotFound is returned by CloudSync.Load when the requested save slot does not exist.
var ErrSlotTooLarge = errors.New("liveops: cloud save slot too large")ErrSlotTooLarge is returned by a CloudSync implementation whose backend refuses a save payload over its size limit. The slot is left as it was.
var ErrTooManySlots = errors.New("liveops: too many cloud save slots")ErrTooManySlots is returned by a CloudSync implementation whose backend refuses a new slot because the player already has as many as it keeps. The slot is not created.
Fonctions
func EncodeCloudSave(v SaveVersion) ([]byte, error)EncodeCloudSave returns the JSON text CloudSyncer stores in the cloud for v: format, version, revision, hash, modified time (RFC 3339, UTC), device and the save data, in that fixed order. Data that is valid UTF-8, such as a save.Store payload, is kept as a readable string; other data is base64 in data_base64. v.Hash is recomputed from v.Data and v.Summary is not stored.
func PayloadHash(payload []byte) stringPayloadHash identifies a raw cloud payload for ConditionalCloudSync: "sha256:" followed by the lowercase hex SHA-256 of payload.
Types
type Analytics struct {
// contains filtered or unexported fields
}Analytics gates event tracking on explicit player consent and optionally persists the consent choice in core.Storage.
Events tracked while Consent is ConsentUnknown or ConsentDenied are dropped immediately — they are never sent and never buffered for later replay.
func NewAnalytics(store core.Storage, key string, provider AnalyticsProvider) *AnalyticsNewAnalytics returns an Analytics gate backed by store under key (DefaultConsentKey when empty) and dispatching consented events to provider. It loads any previously persisted consent choice from store immediately, failing closed to ConsentUnknown when absent or unrecognized.
func NewMemoryAnalytics(provider AnalyticsProvider) *AnalyticsNewMemoryAnalytics returns an Analytics gate that keeps its consent state in memory only, starting in ConsentUnknown.
func (a *Analytics) Consent() ConsentStateConsent returns the current ConsentState. When backed by core.Storage, reading Consent inside a reactive computation subscribes it to storage changes.
func (a *Analytics) Flush() errorFlush flushes the configured provider when Consent is ConsentGranted. When consent is not granted or no provider is set, Flush is a no-op returning nil.
func (a *Analytics) SetClock(now func() time.Time)SetClock sets the clock function used for Event.Time; time.Now is used when nil.
func (a *Analytics) SetConsent(state ConsentState) errorSetConsent updates the consent choice and persists it when backed by core.Storage. Revoking consent (ConsentDenied or ConsentUnknown) immediately stops all subsequent Track calls.
func (a *Analytics) SetProvider(provider AnalyticsProvider)SetProvider replaces the AnalyticsProvider that receives consented events.
func (a *Analytics) Track(name string, props map[string]any) boolTrack dispatches an event to the configured provider only when Consent is ConsentGranted. When consent is ConsentUnknown or ConsentDenied, or when no provider is configured, Track drops the event immediately without buffering and returns false. When consent is granted, props is defensively copied before dispatch and Track returns whether provider.Send succeeded.
type AnalyticsProvider interface {
Send(Event) error
Flush() error
}AnalyticsProvider receives analytics events after explicit opt-in consent. Provider implementations live outside the core game module so no third-party analytics SDK is linked unless chosen by the app.
type BuyResult intBuyResult is how a Buy ended without an error.
const (
// BuyFailed is the result that goes with an error.
BuyFailed BuyResult = iota
// Bought: the purchase went through and was delivered, its credit saved or its unlock owned.
Bought
// BuyPending: the purchase waits for approval, as Ask to Buy's does; Pending reports it until its transaction arrives through the store's updates, which deliver it as Buy would have.
BuyPending
// BuyCancelled: the user closed the store's sheet.
BuyCancelled
)func (r BuyResult) String() stringString returns "failed", "bought", "pending" or "cancelled".
type Choice intChoice is the answer to a Conflict under PolicyAsk.
const (
// ChoiceDefer leaves the conflict unresolved: nothing is written on either side and the next sync asks again.
ChoiceDefer Choice = iota
// ChoiceLocal keeps this device's copy and overwrites (or deletes) the cloud copy.
ChoiceLocal
// ChoiceCloud keeps the cloud copy and overwrites (or deletes) this device's copy. SlotResult.Discarded holds the replaced copy; when it was a valid save envelope and the cloud copy exists, the local save backend also keeps it as its backup.
ChoiceCloud
// ChoiceBoth keeps the cloud copy in the slot and moves this device's copy into a fork slot on both sides. When one side deleted the slot it keeps the copy that exists.
ChoiceBoth
)func (c Choice) String() stringString returns "defer", "local", "cloud", "both" or "unknown".
type CloudChange struct {
// Slots lists the sorted save slot names affected by this change. It may be empty on account-change or initial-sync notifications that did not enumerate individual files.
Slots []string
// Reason explains why the external change arrived.
Reason cloud.ChangeReason
}CloudChange reports save slots updated or deleted externally in platform cloud storage (such as from another device).
type CloudClient struct {
// contains filtered or unexported fields
}CloudClient is the CloudSync of the self-hosted cloud save service in package cloudsave, over HTTPS. It implements ConditionalCloudSync, so a CloudSyncer on it never overwrites another device's upload, and adds the service's version history: Versions, LoadVersion, Restore and Purge.
Its errors wrap the liveops sentinels: ErrSlotNotFound, ErrCloudChanged when a conditional write lost to another device, ErrSlotTooLarge (with the service's limit in the message), ErrTooManySlots, and ErrCloudUnavailable when the network, the service or the token fails, which a sync treats as offline. A done context's error is returned as it is. A CloudClient is safe for concurrent use.
func NewCloudClient(opts CloudClientOptions) (*CloudClient, error)NewCloudClient returns a client for opts, or an error when the URL or the token source is missing or invalid.
func (c *CloudClient) Delete(ctx context.Context, slot string) errorDelete implements CloudSync. The service keeps the slot's history, so Restore can bring it back.
func (c *CloudClient) DeleteIf(ctx context.Context, slot, match string) errorDeleteIf implements ConditionalCloudSync.
func (c *CloudClient) List(ctx context.Context) ([]string, error)List implements CloudSync: the names of the player's live slots, in byte order.
func (c *CloudClient) Load(ctx context.Context, slot string) ([]byte, error)Load implements CloudSync. It checks the payload against the service's ETag.
func (c *CloudClient) LoadVersion(ctx context.Context, slot string, number int64) ([]byte, error)LoadVersion returns the payload of kept version number of slot, as Load returns the current one. It returns ErrSlotNotFound when the version is not kept or is a deletion.
func (c *CloudClient) Purge(ctx context.Context, slot string) errorPurge removes slot and its whole history from the service for good; a slot that does not exist is not an error.
func (c *CloudClient) Restore(ctx context.Context, slot string, number int64) errorRestore makes kept version number the slot's current copy, as a new version written only while the slot still holds the copy Restore read (ErrCloudChanged otherwise). Restoring a deletion deletes the slot.
A payload written by CloudSyncer is re-stamped with the next revision and the current time, so every device sees the restore as the newest copy: one whose copy is unchanged since its last sync downloads it on the next sync, and one with unsynced changes gets a conflict its policy resolves. Other payloads are restored byte for byte.
func (c *CloudClient) Save(ctx context.Context, slot string, data []byte) errorSave implements CloudSync: it replaces the slot whatever it holds.
func (c *CloudClient) SaveIf(ctx context.Context, slot string, data []byte, match string) errorSaveIf implements ConditionalCloudSync.
func (c *CloudClient) Versions(ctx context.Context, slot string) ([]CloudVersion, error)Versions lists the kept versions of slot, newest first, deletions included. It returns ErrSlotNotFound for a slot with no history.
type CloudClientOptions struct {
// URL is the base URL of the cloud save service (package cloudsave), such as "https://saves.example.com". It must use https, except on a loopback host (localhost, 127.0.0.1, ::1) during development. Required.
URL string
// Token returns a current bearer token from the account service for the signed-in player, getting a new one when the last has expired. Every device signed in to the same account reads and writes the same slots. Required.
Token func(ctx context.Context) (string, error)
// HTTPClient sends the requests; http.DefaultClient when nil. The client uses a copy that does not follow redirects. On the web its requests go through the browser's fetch, so the page's origin must be in the service's allowedOrigins.
HTTPClient *http.Client
// Now stamps payloads Restore re-writes; time.Now when nil.
Now func() time.Time
}CloudClientOptions configures NewCloudClient.
type CloudProvider uint8CloudProvider names a platform cloud-save service.
const (
// CloudProviderNone means the platform has no built-in OS cloud-save service through NSGo's cloud package (Windows, Linux, the web).
CloudProviderNone CloudProvider = iota
// CloudProviderICloud is Apple's iCloud ubiquity container on macOS and iOS (including iPadOS and tvOS).
CloudProviderICloud
// CloudProviderPlayGames is Google Play Games Saved Games on Android.
CloudProviderPlayGames
// CloudProviderSteam is Steam Auto-Cloud on desktop targets, which syncs a local directory (such as cx.DataDir() or a subdirectory via DirCloud).
CloudProviderSteam
)func CloudProviderFor(os core.OS) CloudProviderCloudProviderFor returns the built-in OS cloud-save service NSGo's cloud package reaches on os: CloudProviderICloud on macOS and iOS, CloudProviderPlayGames on Android, and CloudProviderNone elsewhere.
func (p CloudProvider) String() stringString returns "none", "icloud", "play-games" or "steam".
type CloudSync interface {
// Load reads the raw bytes stored in slot, returning ErrSlotNotFound if slot does not exist.
Load(ctx context.Context, slot string) ([]byte, error)
// Save writes data to slot, replacing any previous contents.
Save(ctx context.Context, slot string, data []byte) error
// Delete removes slot if it exists.
Delete(ctx context.Context, slot string) error
// List returns the names of all save slots stored for the current player.
List(ctx context.Context) ([]string, error)
}CloudSync is the provider-agnostic cloud-save interface for NSGo games (#196).
PlatformCloud adapts NSGo's cloud package (iCloud on macOS and iOS, Google Play Games Saved Games on Android, and the in-memory store under nsgotest); DirCloud adapts a local directory synced by a desktop storefront such as Steam Auto-Cloud; CloudClient talks to the self-hosted backend in package cloudsave; and games can also supply their own backend or an in-memory mock against this interface.
type CloudSyncOptions struct {
// Local is this device's save backend, such as save.StorageBackend or save.FileBackend. Required.
Local save.Backend
// Cloud is the player's cloud storage. Required.
Cloud CloudSync
// State holds each slot's sync state on this device, as JSON text under StateKey. Required.
State core.Storage
// StateKey is the key prefix CloudSyncer owns in State; DefaultSyncStateKey when empty.
StateKey string
// Device identifies this device in cloud payloads and fork slot names: 1 to 64 ASCII letters, digits, '-' or '_'. Required.
Device string
// Policy resolves conflicts; PolicyNewest when zero.
Policy ConflictPolicy
// Ask answers each conflict under PolicyAsk. It is required with PolicyAsk. It runs inside the sync, on the app's thread, so it must return without waiting for the player: to ask through a dialog, keep the Conflict, return ChoiceDefer, show both summaries, and apply the answer with CloudSyncer.Resolve. An error leaves the slot untouched and is returned by the sync.
Ask func(ctx context.Context, c Conflict) (Choice, error)
// Summarize returns a short, player-facing description of a save payload for Conflict summaries. Optional.
Summarize func(slot string, data []byte) string
// Now returns the current time, used to stamp local writes made through Backend; time.Now when nil.
Now func() time.Time
}CloudSyncOptions configures NewCloudSyncer.
type CloudSyncer struct {
// contains filtered or unexported fields
}CloudSyncer reconciles a device's save slots with cloud storage, detecting slots that changed on both sides since the last sync and resolving them by policy without silently losing either copy.
It remembers, per slot, the content hash and cloud revision both sides agreed on at the last sync (the base). On each sync it compares the local copy, the cloud copy and the base: when only one side differs from the base that side is copied to the other, and when both differ (and from each other) the slot is a conflict. Cloud payloads are JSON text carrying the revision, content hash, modified time and writing device next to the save data.
Write saves through Backend so that each local write is stamped with its time for PolicyNewest and conflict summaries. A CloudSyncer is not safe for concurrent use; call Sync, SyncSlot and Resolve where the app's code runs, as core.Storage requires, or use SyncAsync, SyncSlotAsync and ResolveAsync to run cloud I/O off the engine goroutine while marshaling local storage, sync state and Ask callbacks onto cx's engine goroutine (required with PlatformCloud on Apple and Android devices, and recommended with CloudClient so network I/O does not stall frames).
Before every cloud write it reads the cloud copy again and refuses to write when it changed (ErrCloudChanged). When Cloud implements ConditionalCloudSync, as CloudClient and DirCloud do, the write itself is conditional on that copy, so an upload by another device can never be overwritten: the losing write fails with ErrCloudChanged and the next sync sees both copies as a conflict for the policy to resolve. A plain CloudSync has no conditional write, so an upload by another device that lands between the re-read and the write can still be overwritten; the window is a single Load and Save apart.
func NewCloudSyncer(opts CloudSyncOptions) (*CloudSyncer, error)NewCloudSyncer returns a CloudSyncer for opts, or an error when a required option is missing or invalid.
func (s *CloudSyncer) Backend() save.BackendBackend returns the local save backend wrapped so that every Write and Delete is stamped with the current time in the slot's sync state. Pass it to save.NewStore so PolicyNewest and conflict summaries know when each local copy was written. Its Unwrap method returns the local backend, so a save.SettingsStore built on it keeps settings where the local backend does.
func (s *CloudSyncer) Resolve(ctx context.Context, c Conflict, choice Choice) (SlotResult, error)Resolve applies choice to a conflict reported earlier, typically one that Ask answered with ChoiceDefer so the game could show the player both copies outside the sync. It reads both sides again and applies choice only while they still hold the copies in c (the same existence, content hash and cloud revision); otherwise it writes nothing and returns ErrConflictChanged. ChoiceDefer writes nothing. Resolve works under every policy and does not call Ask.
func (s *CloudSyncer) ResolveAsync(cx *core.Scope, ctx context.Context, c Conflict, choice Choice, done func(SlotResult, error))ResolveAsync runs Resolve asynchronously as SyncAsync does for Sync.
func (s *CloudSyncer) Sync(ctx context.Context) (SyncResult, error)Sync reconciles every slot known locally, in the cloud or in the sync state, in slot-name order.
A slot that fails is skipped and its error joined into the returned error while the others still sync, except when the cloud is unavailable or ctx is done, which stops the sync.
func (s *CloudSyncer) SyncAsync(cx *core.Scope, ctx context.Context, done func(SyncResult, error))SyncAsync runs Sync with cloud I/O off cx's engine goroutine while marshaling local backend, sync state, Summarize, Now and Ask calls onto cx's engine goroutine through cx.Post, then delivers the result to done on the engine goroutine. Use it on Apple and Android devices with PlatformCloud (whose callbacks arrive via cx.Post) and with CloudClient so network I/O does not block frames.
Concurrent SyncAsync, SyncSlotAsync and ResolveAsync calls on the same CloudSyncer are serialized in order. If a local save changes a slot while its cloud read is in flight, SyncAsync refuses to overwrite the local copy (ErrConflictChanged) so the next sync resolves both copies cleanly. Disposing cx stops the sync and skips done.
func (s *CloudSyncer) SyncSlot(ctx context.Context, slot string) (SlotResult, error)SyncSlot reconciles one slot. On error nothing has been written for the slot, except that a failure after a conflict fork was created leaves the fork in place; the next sync uploads it and reuses it rather than creating another.
func (s *CloudSyncer) SyncSlotAsync(cx *core.Scope, ctx context.Context, slot string, done func(SlotResult, error))SyncSlotAsync runs SyncSlot asynchronously as SyncAsync does for Sync.
type CloudVersion struct {
// Number counts the slot's versions from 1; each write or delete adds one.
Number int64
// Deleted marks a version that deleted the slot.
Deleted bool
// Hash is the PayloadHash of the version's payload, empty for a deletion.
Hash string
// Size is the payload's length in bytes.
Size int64
// Created is when the service stored the version.
Created time.Time
}CloudVersion describes one kept version of a slot in the service's history.
type ConditionalCloudSync interface {
CloudSync
// SaveIf writes data to slot only while the slot holds the payload whose PayloadHash is match, or, when match is empty, only while the slot does not exist. Otherwise it writes nothing and returns an error wrapping ErrCloudChanged.
SaveIf(ctx context.Context, slot string, data []byte, match string) error
// DeleteIf removes slot only while it holds the payload whose PayloadHash is match. Otherwise it removes nothing and returns an error wrapping ErrCloudChanged. An empty match succeeds, removing nothing, while slot does not exist.
DeleteIf(ctx context.Context, slot, match string) error
}ConditionalCloudSync is a CloudSync whose backend can write and delete a slot only while it still holds the payload the caller last read, so two devices writing the same slot at once cannot overwrite each other. CloudSyncer uses these methods whenever its Cloud implements them; CloudClient does.
A payload is identified by PayloadHash of its raw bytes, as Load returned them.
type Conflict struct {
// Slot is the save slot name.
Slot string
// Local is this device's copy.
Local SaveVersion
// Cloud is the copy in cloud storage.
Cloud SaveVersion
}Conflict is a slot whose local and cloud copies both changed since this device last synced it, passed to CloudSyncOptions.Ask under PolicyAsk and reported in SlotResult.Conflict. Pass it back to CloudSyncer.Resolve to apply the player's choice later.
type ConflictPolicy intConflictPolicy chooses how CloudSyncer resolves a slot whose local and cloud copies both changed since the last sync.
const (
// PolicyNewest keeps the copy with the later modified time and overwrites the other. When either time is unknown or both are equal it keeps both, as PolicyKeepBoth does, and when one side deleted the slot and the other changed it, it keeps the changed copy.
PolicyNewest ConflictPolicy = iota
// PolicyKeepBoth keeps the cloud copy in the slot and moves the local copy into a new fork slot on both sides, so neither is lost. When one side deleted the slot and the other changed it, it keeps the changed copy.
PolicyKeepBoth
// PolicyAsk passes each conflict, with a summary of both copies, to CloudSyncOptions.Ask and applies the player's Choice.
PolicyAsk
)func (p ConflictPolicy) String() stringString returns "newest", "keep-both", "ask" or "unknown".
type ConsentState intConsentState represents the player's analytics consent choice.
const (
// ConsentUnknown is the default before the player chooses. No events are sent or buffered.
ConsentUnknown ConsentState = iota
// ConsentDenied records that the player declined or revoked analytics. No events are sent or buffered.
ConsentDenied
// ConsentGranted records explicit opt-in consent. Only in this state may events be dispatched to the provider.
ConsentGranted
)func (s ConsentState) String() stringString returns "unknown", "denied" or "granted".
type CrashOptions struct {
// HistorySize is how many recent steps the ring buffer keeps; DefaultHistorySize (120) when <= 0.
HistorySize int
// Reporter receives every CrashReport produced by a recovered panic.
Reporter func(CrashReport)
// CaptureState optionally returns a JSON-marshalable snapshot of the game's state when a panic is caught.
CaptureState func() any
// Metadata holds initial key-value pairs copied into every CrashReport (such as app version, target OS or scene name).
Metadata map[string]string
// Rethrow re-panics with the recovered value after Reporter returns.
Rethrow bool
// Now returns the clock time for CrashReport.Timestamp; time.Now when nil.
Now func() time.Time
}CrashOptions configures a CrashReporter.
type CrashReport struct {
// Timestamp is when the panic was caught, from CrashOptions.Now or time.Now.
Timestamp time.Time `json:"timestamp"`
// Panic is the raw value returned by recover. When marshaled to JSON, an error that does not implement json.Marshaler or encoding.TextMarshaler, or any non-JSON-marshalable value, is encoded as its string message.
Panic any `json:"panic,omitempty"`
// Message is fmt.Sprint(Panic).
Message string `json:"message"`
// Stack is the goroutine stack trace captured at recovery via runtime/debug.Stack.
Stack string `json:"stack"`
// Step is the reporter's monotonic step counter at the time of the crash.
Step uint64 `json:"step"`
// LastSteps holds the buffered steps in chronological order, oldest to newest.
LastSteps []StepRecord `json:"last_steps,omitempty"`
// State is the optional snapshot returned by CrashOptions.CaptureState.
State any `json:"state,omitempty"`
// Metadata holds a copy of the reporter's metadata key-value pairs (such as app version, target OS or scene name).
Metadata map[string]string `json:"metadata,omitempty"`
}CrashReport is a JSON-marshalable snapshot built when a guarded callback panics.
func (r CrashReport) MarshalJSON() ([]byte, error)MarshalJSON encodes r as JSON, ensuring Panic values that are plain errors or non-JSON types serialize cleanly as strings rather than empty objects or marshal errors.
type CrashReporter struct {
// contains filtered or unexported fields
}CrashReporter records recent simulation steps in a fixed-size ring buffer and catches panics in guarded callbacks or game.Loop runs, building a CrashReport for the app's Reporter.
func NewCrashReporter(opts CrashOptions) *CrashReporterNewCrashReporter returns a CrashReporter configured by opts, pre-allocating its step ring buffer so steady-state RecordStep calls perform no heap allocations.
func (c *CrashReporter) DeleteMetadata(key string)DeleteMetadata removes a metadata key from subsequent CrashReports.
func (c *CrashReporter) GuardLoop(l *game.Loop)GuardLoop wraps l.Update and l.Draw in place with panic recovery and step recording. If l.Update does not call RecordStep itself during a step, the guard records an "update" step automatically (including for a step that panics).
func (c *CrashReporter) LastSteps() []StepRecordLastSteps returns a chronological copy (oldest to newest) of the buffered steps.
func (c *CrashReporter) RecordStep(dt time.Duration, summary string) uint64RecordStep appends a step to the ring buffer and returns its monotonic step number. It allocates nothing in steady state.
func (c *CrashReporter) RecordStepData(dt time.Duration, summary string, data any) uint64RecordStepData appends a step with optional structured data to the ring buffer and returns its monotonic step number. It allocates nothing in steady state.
func (c *CrashReporter) Reset()Reset clears the buffered steps without reallocating the ring buffer. The monotonic step counter continues from its current value.
func (c *CrashReporter) RunSafe(fn func()) (panicked bool)RunSafe runs fn and recovers any panic into a CrashReport passed to Reporter. It reports whether fn panicked. When CrashOptions.Rethrow is true, RunSafe re-panics with the original value after Reporter returns.
func (c *CrashReporter) SetMetadata(key, value string)SetMetadata sets or updates a metadata key included in subsequent CrashReports.
func (c *CrashReporter) Step() uint64Step returns the reporter's current monotonic step count.
func (c *CrashReporter) WrapLoop(l *game.Loop) *game.LoopWrapLoop returns a new *game.Loop that delegates to l.Update and l.Draw with panic recovery and step recording. If l.Update does not call RecordStep itself during a step, the wrapper records an "update" step automatically (including for a step that panics). Returns nil when l is nil.
type DirCloud struct {
// contains filtered or unexported fields
}DirCloud implements ConditionalCloudSync over a directory on disk, storing each slot as "<slot>.json" with atomic temp-file writes and directory sync.
It is designed for desktop storefronts such as Steam Auto-Cloud, which synchronize a configured directory (such as a subdirectory of cx.DataDir()) across machines without a native cloud SDK. Pairing DirCloud with CloudSyncer gives Steam builds the same CloudSync and conflict-resolution pipeline as iCloud and Google Play Games builds; games that do not need CloudSyncer's conflict envelopes can also point Steam Auto-Cloud directly at save.FileBackend(cx.DataDir()).
DirCloud is safe for concurrent use within a process.
func NewDirCloud(dir string) (*DirCloud, error)NewDirCloud returns a DirCloud storing slot files inside dir, or an error when dir is empty (such as cx.DataDir() on the web). The directory is created on the first write.
func (c *DirCloud) Delete(ctx context.Context, slot string) errorDelete implements CloudSync.
func (c *DirCloud) DeleteIf(ctx context.Context, slot, match string) errorDeleteIf implements ConditionalCloudSync.
func (c *DirCloud) Dir() stringDir returns the cleaned directory path where DirCloud keeps slot files.
func (c *DirCloud) List(ctx context.Context) ([]string, error)List implements CloudSync. It returns the sorted names of all valid save slots in the directory, or nil if the directory does not exist yet.
func (c *DirCloud) Load(ctx context.Context, slot string) ([]byte, error)Load implements CloudSync.
func (c *DirCloud) Save(ctx context.Context, slot string, data []byte) errorSave implements CloudSync.
func (c *DirCloud) SaveIf(ctx context.Context, slot string, data []byte, match string) errorSaveIf implements ConditionalCloudSync.
type Event struct {
Name string `json:"name"`
Properties map[string]any `json:"properties,omitempty"`
Time time.Time `json:"time"`
}Event is one analytics event delivered to an AnalyticsProvider after explicit consent.
type Ledger struct {
// Credited are the IDs of consumable transactions credited, oldest first.
Credited []string `json:"credited,omitempty"`
// Revoked are the IDs of credited consumable transactions whose refund or revocation was taken back, oldest first.
Revoked []string `json:"revoked,omitempty"`
}Ledger records the transactions a game has credited and revoked, so each is applied once across runs. Keep it inside the state PurchasesOptions.Save writes, beside the coins, lives or other state a credit changes: the credit and its record then reach the disk in one write, so a kill before that write loses both and the store's redelivery credits it again, and a kill after it finds the record and only finishes the transaction.
func (l Ledger) HasCredited(id string) boolHasCredited reports whether the transaction whose ID is id was credited.
func (l Ledger) HasRevoked(id string) boolHasRevoked reports whether the refund or revocation of the transaction whose ID is id was taken back.
type PlatformCloud struct {
// contains filtered or unexported fields
}PlatformCloud implements CloudSync over NSGo's package cloud: Apple iCloud ubiquity containers on macOS and iOS, Google Play Games Saved Games on Android, and an isolated per-app in-memory store in nsgotest. On platforms without a built-in OS cloud store (Windows, Linux, the web), every operation fails with ErrCloudUnavailable and never silently drops writes.
Each save slot is stored as "<Prefix><slot>.json" (default "save.<slot>.json") and validated with save.ValidateSlot. Errors wrap liveops's sentinels alongside package cloud's sentinels: ErrCloudUnavailable (cloud.ErrUnavailable), ErrSlotNotFound (cloud.ErrNotFound), and ErrCloudConflict (cloud.ErrConflict / *cloud.ConflictError).
On real Apple and Android targets (where cx.CloudStore() is nil), package cloud delivers its callbacks on cx's engine goroutine through cx.Post, so blocking CloudSync methods (Load, Save, Delete, List) must be called off the engine goroutine—such as through CloudSyncer.SyncAsync—or they would block the goroutine needed to deliver their answer. Under nsgotest (where cx.CloudStore() is non-nil), operations run directly against the per-app store and are safe from any goroutine, including synchronous CloudSyncer.Sync calls in tests.
func NewPlatformCloud(cx *core.Scope, opts PlatformCloudOptions) (*PlatformCloud, error)NewPlatformCloud returns a PlatformCloud bound to cx, or an error if cx is nil or opts.Prefix is invalid. Call it on cx's engine goroutine with a scope that lives as long as cloud sync runs (such as the app's root scope).
func (c *PlatformCloud) Available() boolAvailable reports whether platform cloud storage is reachable right now (cx.Env().CanUseCloudStorage()). Read in a reactive computation on the engine goroutine, it updates when availability changes.
func (c *PlatformCloud) Delete(ctx context.Context, slot string) errorDelete implements CloudSync. Deleting an absent slot succeeds when cloud storage is available and returns ErrCloudUnavailable when it is not.
func (c *PlatformCloud) FileName(slot string) (string, error)FileName returns the platform cloud file or snapshot name for slot ("<Prefix><slot>.json"), or an error wrapping save.ErrInvalidSlot when slot is invalid.
func (c *PlatformCloud) List(ctx context.Context) ([]string, error)List implements CloudSync. It lists the sorted names of valid save slots matching this PlatformCloud's prefix, ignoring other files in the cloud container.
func (c *PlatformCloud) Load(ctx context.Context, slot string) ([]byte, error)Load implements CloudSync. It returns ErrSlotNotFound when slot does not exist, ErrCloudUnavailable when cloud storage is unavailable or cx is disposed, and ErrCloudConflict (also wrapping *cloud.ConflictError) when unresolved native platform conflicts exist.
func (c *PlatformCloud) OnConflict(resolve func(PlatformConflict)) (stop func())OnConflict subscribes resolve to native platform version conflicts for slots matching this PlatformCloud's prefix. Notifications are delivered on cx's engine goroutine and stop automatically when stop is called or cx is disposed.
func (c *PlatformCloud) Prefix() stringPrefix returns the file-name prefix prepended to each slot name.
func (c *PlatformCloud) Provider() CloudProviderProvider returns the built-in OS cloud-save service of the platform cx runs on (CloudProviderICloud, CloudProviderPlayGames, or CloudProviderNone), whether or not the player is signed in.
func (c *PlatformCloud) Save(ctx context.Context, slot string, data []byte) errorSave implements CloudSync. It writes data to slot and returns ErrCloudUnavailable rather than silently dropping writes when cloud storage is unavailable.
func (c *PlatformCloud) WatchChanges(onChange func(CloudChange)) (stop func())WatchChanges subscribes onChange to external cloud-save changes for slots matching this PlatformCloud's prefix. Notifications are delivered on cx's engine goroutine and stop automatically when stop is called or cx is disposed. Account-change notifications (cloud.ChangeAccount) and container-wide initial-sync notifications are delivered even when the platform did not enumerate individual file names.
type PlatformCloudOptions struct {
// Prefix is prepended to each slot name to form its cloud file or snapshot name ("<Prefix><slot>.json"); DefaultCloudPrefix ("save.") when empty. Must not start with '/' or '.', or contain "..", '\', "//" or control characters. Avoid '/' when targeting Android, where Google Play Games snapshot names do not accept path separators.
Prefix string
}PlatformCloudOptions configures NewPlatformCloud.
type PlatformConflict struct {
// Slot is the save slot name.
Slot string
// Local holds the local cloud payload bytes (which may be a CloudSyncer JSON envelope decodable with DecodeCloudSave).
Local []byte
// Remote holds the conflicting remote cloud payload bytes.
Remote []byte
// LocalTime is the modification time reported for Local, if known.
LocalTime time.Time
// RemoteTime is the modification time reported for Remote, if known.
RemoteTime time.Time
// Resolve commits the winning payload bytes to platform cloud storage, clearing the native conflict.
Resolve func(chosen []byte) error
}PlatformConflict describes a version conflict reported by the native platform cloud backend (iCloud NSFileVersion or Google Play Games Saved Games) for one save slot.
type Purchases struct {
// contains filtered or unexported fields
}Purchases sells a game's in-app products over NSGo's purchase services: it credits consumables into the save exactly once, keeps unlocks and subscriptions from the store's entitlements, restores them, follows purchases waiting for approval and hands each transaction to an optional server before delivering it. Its methods run on the scope's goroutine, as NSGo's callbacks do.
func NewPurchases(cx *core.Scope, opts PurchasesOptions) *PurchasesNewPurchases starts selling with opts under cx: it registers for the store's transaction updates, which hand over unfinished transactions as the app starts, and reads the user's current entitlements. Call it as the app starts, before the first frame, so no update waits.
func (p *Purchases) Available() boolAvailable reports whether this platform and build reach a store, core.Env.CanPurchase; read in a reactive computation, it follows it.
func (p *Purchases) Buy(product string, quantity int, done func(BuyResult, error))Buy buys quantity of product (0 is 1) through the store's sheet and answers done once: Bought after the transaction is verified and delivered, BuyPending or BuyCancelled, or BuyFailed with the error. done may be nil.
func (p *Purchases) Entitlement(product string) (core.Transaction, bool)Entitlement returns the latest transaction that gives the user product, and whether there is one, whatever its expiration date.
func (p *Purchases) Owned(product string) boolOwned reports whether the user owns product now: a non-consumable or a subscription that is neither refunded nor past its expiration date at the scope's wall time. Read in a reactive computation, it follows purchases, refunds and restores.
func (p *Purchases) Pending(product string) boolPending reports whether a purchase of product waits for approval. Read in a reactive computation, it follows the approval. A request the approver declines produces no transaction, so Pending stays true until a transaction for product arrives, from a later Buy too, or the app restarts.
func (p *Purchases) Refresh(done func(error))Refresh reads the user's current entitlements from the store and makes them what Owned reports, then answers done, which may be nil. An unlock delivered while the answer was on its way stays, unless the answer holds a later transaction for it, and one refunded meanwhile stays gone. NewPurchases calls it; call it again as the app returns to the foreground, which is also when Owned next notices a subscription that expired. An error goes to done, or to OnError when done is nil.
func (p *Purchases) Restore(done func(error))Restore has the store bring the user's purchases up to date, which may ask them to sign in, then refreshes what Owned reports, and answers done, which may be nil: nil, or the store's error, core.PurchaseCancelled when the user declined to sign in. Call it only from a Restore Purchases button the user presses.
type PurchasesOptions struct {
// Ledger is the game's record of credited transactions, which Save must persist along with the state Credit and Revoke change. It is required.
Ledger *Ledger
// Credit applies a consumable transaction to the game's state, tr.Quantity of tr.ProductID. It runs at most once per transaction ID, across runs too, as long as Save persists Ledger with that state.
Credit func(tr core.Transaction)
// Revoke takes back what a credited consumable gave when the store refunds or revokes it; nil keeps the credit. It runs at most once per transaction ID, as Credit does.
Revoke func(tr core.Transaction)
// Save persists the game's save, Ledger included, after Credit or Revoke changed it. A transaction is finished only once Save returns nil: after an error it stays unfinished, the store hands it to the app again at its next launch, and the ledger kept in memory or on disk keeps Credit from running twice. It is required for consumables.
Save func() error
// Verify hands tr, whose Signed is the store's JWS, to the game's server and calls done once with nil to accept it or an error to refuse it, from any goroutine. A refused transaction is neither delivered nor finished. nil accepts what the device verified, Transaction.Verified.
Verify func(tr core.Transaction, done func(error))
// AccountToken is the UUID of the game's own that each purchase carries to the store and the game's server, "" for none.
AccountToken string
// OnError hears failures that no Buy or Restore answers: a transaction from the store's updates refused, unsaved or not finished, or entitlements the store could not answer.
OnError func(tr core.Transaction, err error)
}PurchasesOptions configures NewPurchases.
type SaveVersion struct {
// Exists is false when this side deleted the slot; the other fields are then zero.
Exists bool
// Revision is the cloud revision: the cloud copy's own, or for the local copy the revision it was last synced at (0 when never synced).
Revision int64
// Hash is "sha256:" followed by the hex SHA-256 of Data.
Hash string
// Modified is when the copy was last written, zero when unknown (a local write that bypassed CloudSyncer.Backend, or a plain cloud payload). A local time counts only for the exact copy it was recorded with: a later write that bypassed Backend makes it unknown.
Modified time.Time
// Device is the ID of the device that wrote the copy, empty when unknown.
Device string
// Summary is CloudSyncOptions.Summarize's text for Data, such as "Level 12, 3h 40m played".
Summary string
// Data is the raw save payload.
Data []byte
}SaveVersion describes one side's copy of a slot in a Conflict or a SlotResult.
func DecodeCloudSave(raw []byte) (SaveVersion, error)DecodeCloudSave reads a cloud payload. A JSON object whose "format" is CloudSaveFormat is decoded strictly (unknown fields, a newer version, a revision below 1 or at math.MaxInt64, a hash that does not match the data or a malformed value return an error wrapping ErrCorruptCloudSave); any other payload is a plain save written without CloudSyncer and is returned as revision 0 with no modified time or device.
type SlotResult struct {
// Slot is the save slot name.
Slot string
// Outcome is what was done.
Outcome SyncOutcome
// Conflict is set when both copies had changed, whatever the outcome.
Conflict *Conflict
// Fork is the slot the local copy was moved to under OutcomeKeptBoth.
Fork string
// Discarded is the copy a resolution replaced under OutcomeKeptLocal or OutcomeKeptCloud, so a game can show or archive it.
Discarded *SaveVersion
}SlotResult reports what a sync did to one slot.
type StepRecord struct {
// Step is the 1-based monotonic step counter assigned when the step was recorded.
Step uint64 `json:"step"`
// DT is the fixed simulation step duration passed to RecordStep or Loop.Update.
DT time.Duration `json:"dt"`
// Summary is an optional short label describing what ran in the step.
Summary string `json:"summary,omitempty"`
// Data holds optional structured context attached to the step.
Data any `json:"data,omitempty"`
}StepRecord describes one recorded step in a CrashReporter's fixed-size ring buffer.
type SyncOutcome intSyncOutcome says what CloudSyncer did to one slot.
const (
// OutcomeUpToDate means both sides already held the same copy.
OutcomeUpToDate SyncOutcome = iota
// OutcomeUploaded means only the local copy had changed, and it was uploaded.
OutcomeUploaded
// OutcomeDownloaded means only the cloud copy had changed, and it was written locally.
OutcomeDownloaded
// OutcomeDeletedCloud means the slot was deleted locally and unchanged in the cloud, so the cloud copy was deleted.
OutcomeDeletedCloud
// OutcomeDeletedLocal means the slot was deleted in the cloud and unchanged locally, so the local copy was deleted.
OutcomeDeletedLocal
// OutcomeKeptLocal means a conflict was resolved in favour of the local copy; SlotResult.Discarded holds the cloud copy it replaced.
OutcomeKeptLocal
// OutcomeKeptCloud means a conflict was resolved in favour of the cloud copy; SlotResult.Discarded holds the local copy it replaced. When that copy was a valid save envelope and the cloud copy exists, the local save backend also keeps it as its backup; otherwise Discarded is the only copy left.
OutcomeKeptCloud
// OutcomeKeptBoth means a conflict was resolved by keeping the cloud copy in the slot and moving the local copy to SlotResult.Fork on both sides.
OutcomeKeptBoth
// OutcomeDeferred means a conflict was left unresolved, by ChoiceDefer under PolicyAsk or passed to CloudSyncer.Resolve; nothing was written.
OutcomeDeferred
)func (o SyncOutcome) String() stringString returns a lowercase, hyphenated name such as "up-to-date" or "kept-both".
type SyncResult struct {
// Slots holds one entry for each slot that synced without error.
Slots []SlotResult
}SyncResult reports what CloudSyncer.Sync did to each slot, sorted by slot name.
func (r SyncResult) Conflicts() []SlotResultConflicts returns the slot results that held a conflict.