// Manager: the thread-safe multi-version snapshot registry (the Go port of// the RustyChickpeas manager layer). Snapshots are immutable, so the// registry is a mutex-guarded map of shared pointers.package chickpeasimport// LatestVersion is the registry key AddSnapshot uses for a snapshot that// carries no version string.constLatestVersion = "latest"// Manager holds named immutable snapshots.typeManagerstruct { mu sync.RWMutex snapshots map[string]*Snapshot}// NewManager returns an empty registry.func () *Manager {return &Manager{snapshots: map[string]*Snapshot{}}}// AddSnapshot registers g under its own version string, or LatestVersion// when it has none, replacing any previous snapshot under that key.func ( *Manager) ( *Snapshot) { , := .Version()if ! || == "" { = LatestVersion } .AddSnapshotWithVersion(, )}// AddSnapshotWithVersion registers g under an explicit version key.func ( *Manager) ( string, *Snapshot) { .mu.Lock()defer .mu.Unlock() .snapshots[] = }// Snapshot returns the snapshot registered under version; ok is false when// absent.func ( *Manager) ( string) (*Snapshot, bool) { .mu.RLock()defer .mu.RUnlock() , := .snapshots[]return , }// Versions lists the registered version keys (unordered).func ( *Manager) () []string { .mu.RLock()defer .mu.RUnlock() := make([]string, 0, len(.snapshots))for := range .snapshots { = append(, ) }return}// RemoveSnapshot drops the snapshot under version, reporting whether one// was present.func ( *Manager) ( string) bool { .mu.Lock()defer .mu.Unlock() , := .snapshots[]delete(.snapshots, )return}// Len is the number of registered snapshots.func ( *Manager) () int { .mu.RLock()defer .mu.RUnlock()returnlen(.snapshots)}// Clear drops every registered snapshot.func ( *Manager) () { .mu.Lock()defer .mu.Unlock()clear(.snapshots)}
The pages are generated with Goldsv0.8.7. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.