Documentation
¶
Overview ¶
Package cloud provides provider-neutral cloud key-value and file/snapshot storage across platforms: iCloud Key-Value Store and ubiquity containers on macOS and iOS, Google Play Games Saved Games on Android, and an isolated per-app in-memory store in nsgotest.
All operations are asynchronous and deliver their callbacks on the engine goroutine through core.Scope.Post; callbacks whose scope has been disposed never run. WatchChanges and OnConflict automatically clean up when cx is disposed.
Unavailable accounts, missing entitlements, or platforms without a cloud provider (such as Windows, Linux and the web) always fail with ErrUnavailable and never silently drop writes. On desktop stores such as Steam, Steam Auto-Cloud syncs core.Scope.DataDir directly without using this package.
Index ¶
- Variables
- func Delete(cx *core.Scope, key string, done func(err error))
- func DeleteFile(cx *core.Scope, name string, done func(err error))
- func Get(cx *core.Scope, key string, done func(value []byte, err error))
- func Keys(cx *core.Scope, done func(keys []string, err error))
- func ListFiles(cx *core.Scope, done func(names []string, err error))
- func OnConflict(cx *core.Scope, resolve func(Conflict)) (stop func())
- func ReadFile(cx *core.Scope, name string, done func(data []byte, err error))
- func Set(cx *core.Scope, key string, value []byte, done func(err error))
- func WatchChanges(cx *core.Scope, onChange func(ChangeEvent)) (stop func())
- func WriteFile(cx *core.Scope, name string, data []byte, done func(err error))
- type ChangeEvent
- type ChangeReason
- type Conflict
- type ConflictError
Constants ¶
This section is empty.
Variables ¶
var ( ErrUnavailable = core.ErrCloudUnavailable // ErrNotFound reports that a requested key or file does not exist. ErrNotFound = core.ErrCloudNotFound // ErrConflict reports that a cloud file or key has conflicting local and remote versions that must be resolved. ErrConflict = core.ErrCloudConflict )
Sentinel errors returned by package cloud operations.
Functions ¶
func Delete ¶
Delete removes key from the cloud key-value store and delivers the result to done on the engine goroutine. Deleting a missing key succeeds when cloud storage is available; an unavailable store returns ErrUnavailable.
func DeleteFile ¶
DeleteFile removes the cloud file or snapshot named name and delivers the result to done on the engine goroutine. Deleting a missing file succeeds when cloud storage is available; an unavailable store returns ErrUnavailable.
func Get ¶
Get reads the value for key from the cloud key-value store and delivers the result to done on the engine goroutine. It returns ErrNotFound if key does not exist and ErrUnavailable if cloud storage is unavailable.
func Keys ¶
Keys lists all keys currently present in the cloud key-value store, sorted, and delivers them to done on the engine goroutine.
func ListFiles ¶
ListFiles lists all cloud files or snapshots currently stored, sorted, and delivers them to done on the engine goroutine.
func OnConflict ¶
OnConflict subscribes resolve to cloud version conflicts. Notifications are delivered on the engine goroutine and the subscription is automatically removed when cx is disposed or stop is called.
func ReadFile ¶
ReadFile reads the cloud file or snapshot named name and delivers its bytes to done on the engine goroutine. It returns ErrNotFound if missing, *ConflictError (unwrapping to ErrConflict) if unresolved conflicts exist, or ErrUnavailable if cloud storage is unavailable.
func Set ¶
Set writes value for key in the cloud key-value store and delivers the result to done on the engine goroutine. It returns ErrUnavailable if cloud storage is unavailable and never silently drops writes.
func WatchChanges ¶
func WatchChanges(cx *core.Scope, onChange func(ChangeEvent)) (stop func())
WatchChanges subscribes onChange to external cloud key-value and file changes. Notifications are delivered on the engine goroutine and the subscription is automatically removed when cx is disposed or stop is called.
Types ¶
type ChangeEvent ¶
type ChangeEvent = core.CloudChangeEvent
ChangeEvent describes keys and files changed externally in cloud storage.
type ChangeReason ¶
type ChangeReason = core.CloudChangeReason
ChangeReason explains why an external cloud storage change arrived.
const ( // ChangeServer reports data updated from another device or the server. ChangeServer ChangeReason = core.CloudChangeServer // ChangeInitialSync reports values downloaded on initial sync after install or sign-in. ChangeInitialSync ChangeReason = core.CloudChangeInitialSync // ChangeQuotaViolation reports that the cloud key-value store exceeded its quota. ChangeQuotaViolation ChangeReason = core.CloudChangeQuotaViolation // ChangeAccount reports that the signed-in cloud account changed. ChangeAccount ChangeReason = core.CloudChangeAccount )
type Conflict ¶
type Conflict = core.CloudConflict
Conflict describes a conflicting remote version of a cloud file or key along with a Resolve function that commits the winning bytes.
type ConflictError ¶
type ConflictError = core.CloudConflictError
ConflictError describes a conflict between local and remote versions of a cloud key or file. It unwraps to ErrConflict.