Adds StorageDriverFactory, unifying creation of StorageDrivers
Custom storage drivers can register a factory to create the driver by name, similar to the database/sql package's Register and Open factory.Create returns an in-process driver if registered or an IPC driver if one can be found, erroring otherwise This standardizes parameter passing for creation of storage drivers Also adds documentation for storagedriver package and children
This commit is contained in:
parent
ff81f3a719
commit
ca0084fad1
15 changed files with 290 additions and 79 deletions
|
@ -10,14 +10,31 @@ import (
|
|||
"sync"
|
||||
|
||||
"github.com/docker/docker-registry/storagedriver"
|
||||
"github.com/docker/docker-registry/storagedriver/factory"
|
||||
)
|
||||
|
||||
const DriverName = "inmemory"
|
||||
|
||||
func init() {
|
||||
factory.Register(DriverName, &inMemoryDriverFactory{})
|
||||
}
|
||||
|
||||
// Implements the factory.StorageDriverFactory interface
|
||||
type inMemoryDriverFactory struct{}
|
||||
|
||||
func (factory *inMemoryDriverFactory) Create(parameters map[string]string) (storagedriver.StorageDriver, error) {
|
||||
return New(), nil
|
||||
}
|
||||
|
||||
// InMemory Storage Driver backed by a map
|
||||
// Intended solely for example and testing purposes
|
||||
type InMemoryDriver struct {
|
||||
storage map[string][]byte
|
||||
mutex sync.RWMutex
|
||||
}
|
||||
|
||||
func NewDriver() *InMemoryDriver {
|
||||
// Constructs a new InMemoryDriver
|
||||
func New() *InMemoryDriver {
|
||||
return &InMemoryDriver{storage: make(map[string][]byte)}
|
||||
}
|
||||
|
||||
|
|
|
@ -13,8 +13,8 @@ func Test(t *testing.T) { TestingT(t) }
|
|||
|
||||
func init() {
|
||||
inmemoryDriverConstructor := func() (storagedriver.StorageDriver, error) {
|
||||
return NewDriver(), nil
|
||||
return New(), nil
|
||||
}
|
||||
testsuites.RegisterInProcessSuite(inmemoryDriverConstructor, testsuites.NeverSkip)
|
||||
testsuites.RegisterIPCSuite("inmemory", nil, testsuites.NeverSkip)
|
||||
testsuites.RegisterIPCSuite(DriverName, nil, testsuites.NeverSkip)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue