image-storage-interfaces/register.go

55 lines
1.4 KiB
Go

package storage
import (
"sort"
"sync"
"git.thisco.de/vbatts/image-storage-interfaces/driver"
)
var (
storageDriversMu sync.RWMutex
storageDrivers = make(map[string]driver.Driver)
)
// Drivers returns a sorted list of the registered drivers
func Drivers() []string {
storageDriversMu.Lock()
defer storageDriversMu.Unlock()
var list []string
for name, _ := range storageDrivers {
list = append(list, name)
}
sort.Strings(list)
return list
}
// Register makes a database driver available by the provided name. If Register
// is called twice with the same name or if driver is nil, it panics.
func Register(name string, driver driver.Driver) {
storageDriversMu.Lock()
defer storageDriversMu.Unlock()
if driver == nil {
panic("storage: Register driver is nil")
}
if _, dup := storageDrivers[name]; dup {
panic("storage: Register called twice for driver " + name)
}
storageDrivers[name] = driver
}
// OpenHandle a storage handle using the specified storage driver name and a
// rootPath for that driver to operate in.
func OpenHandle(name string, rootPath string) (*S, error) {
return nil, nil
}
// S is a storage handle for the storage and management of filesystem trees.
//
// Operations on an handle instance are intended to be safe for concurrent use.
// Though this would likely not be safe for two competing instances to be
// operating on the same rootPath (more thought needed here).
type S struct {
}