-
Notifications
You must be signed in to change notification settings - Fork 11
/
manager_factory.go
executable file
·39 lines (34 loc) · 1.17 KB
/
manager_factory.go
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
package dsc
import (
"fmt"
)
type managerFactoryProxy struct{}
//Create creates a new manager for the passed in config.
func (f managerFactoryProxy) Create(config *Config) (Manager, error) {
if config.DriverName == "" {
return nil, fmt.Errorf("DriverName was empty %v", config)
}
factory, err := GetManagerFactory(config.DriverName)
if err != nil {
return nil, fmt.Errorf("failed to lookup manager factory for `%v`, make sure you have imported required implmentation", config.DriverName)
}
config.Init()
return factory.Create(config)
}
//CreateFromURL create a new manager from URL, url resource should be a JSON Config
func (f managerFactoryProxy) CreateFromURL(URL string) (Manager, error) {
config, err := NewConfigFromURL(URL)
if err != nil {
return nil, err
}
factory, err := GetManagerFactory(config.DriverName)
if err != nil {
return nil, fmt.Errorf("failed to lookup manager factory for `%v`, make sure you have imported required implmentation", config.DriverName)
}
return factory.Create(config)
}
//NewManagerFactory create a new manager factory.
func NewManagerFactory() ManagerFactory {
var manager ManagerFactory = &managerFactoryProxy{}
return manager
}