-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathregistry.go
More file actions
40 lines (35 loc) · 1.22 KB
/
registry.go
File metadata and controls
40 lines (35 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package storage
import "context"
import storagecore "github.com/goforj/storage/storagecore"
// DriverFactory constructs a Storage for a given normalized disk configuration.
// @group Construction
//
// Example: declare a driver factory
//
// factory := storage.DriverFactory(func(ctx context.Context, cfg storage.ResolvedConfig) (storage.Storage, error) {
// return nil, nil
// })
// _ = factory
type DriverFactory func(ctx context.Context, cfg ResolvedConfig) (Storage, error)
// RegisterDriver makes a driver available to the Manager. It panics on duplicate registrations.
// @group Manager
//
// Example: register a custom driver
//
// storage.RegisterDriver("memory", func(ctx context.Context, cfg storage.ResolvedConfig) (storage.Storage, error) {
// return nil, nil
// })
func RegisterDriver(name string, factory DriverFactory) {
storagecore.RegisterDriver(name, func(ctx context.Context, cfg storagecore.ResolvedConfig) (storagecore.Storage, error) {
return factory(ctx, cfg)
})
}
func lookupDriver(name string) (DriverFactory, bool) {
factory, ok := storagecore.LookupDriver(name)
if !ok {
return nil, false
}
return func(ctx context.Context, cfg ResolvedConfig) (Storage, error) {
return factory(ctx, cfg)
}, true
}