-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathfile_manager_factory.go
executable file
·47 lines (40 loc) · 1.34 KB
/
file_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
40
41
42
43
44
45
46
47
package dsc
import (
"github.com/viant/toolbox"
)
type jsonFileManagerFactory struct{}
func (f *jsonFileManagerFactory) Create(config *Config) (Manager, error) {
var connectionProvider = newFileConnectionProvider(config)
fileManager := NewFileManager(toolbox.NewJSONEncoderFactory(), toolbox.NewJSONDecoderFactory(), "", config)
super := NewAbstractManager(config, connectionProvider, fileManager)
fileManager.AbstractManager = super
err := fileManager.Init()
if err != nil {
return nil, err
}
return fileManager, nil
}
func (f jsonFileManagerFactory) CreateFromURL(URL string) (Manager, error) {
config, err := NewConfigFromURL(URL)
if err != nil {
return nil, err
}
return f.Create(config)
}
type delimiteredFileManagerFactory struct {
delimiter string
}
func (f *delimiteredFileManagerFactory) Create(config *Config) (Manager, error) {
var connectionProvider = newFileConnectionProvider(config)
fileManager := NewFileManager(&delimiterEncoderFactory{delimiter: f.delimiter}, &delimiterDecoderFactory{}, f.delimiter, config)
super := NewAbstractManager(config, connectionProvider, fileManager)
fileManager.AbstractManager = super
return fileManager, nil
}
func (f delimiteredFileManagerFactory) CreateFromURL(URL string) (Manager, error) {
config, err := NewConfigFromURL(URL)
if err != nil {
return nil, err
}
return f.Create(config)
}