forked from romnn/mongoimport
-
Notifications
You must be signed in to change notification settings - Fork 0
/
source.go
54 lines (43 loc) · 1.15 KB
/
source.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
48
49
50
51
52
53
54
package mongoimport
import (
"github.com/grittaweisheit/mongoimport/loaders"
)
// Datasource ...
type Datasource struct {
Files []string
DatabaseName string
Collection string
Loader loaders.Loader
PostLoad PostLoadHook
PreDump PreDumpHook
UpdateFilter UpdateFilterHook
EmptyCollection bool
Sanitize bool
}
func (s Datasource) getHooks() (PostLoadHook, PreDumpHook) {
var postLoadHook PostLoadHook
var preDumpHook PreDumpHook
if s.PostLoad != nil {
postLoadHook = s.PostLoad
} else {
postLoadHook = defaultPostLoad
}
if s.PreDump != nil {
preDumpHook = s.PreDump
} else {
preDumpHook = defaultPreDump
}
return postLoadHook, preDumpHook
}
// PostLoadHook ...
type PostLoadHook func(loaded map[string]interface{}) (interface{}, error)
// PreDumpHook ...
type PreDumpHook func(loaded interface{}) (interface{}, error)
// UpdateFilterHook ...
type UpdateFilterHook func(loaded interface{}) (interface{}, error)
func defaultPostLoad(loaded map[string]interface{}) (interface{}, error) {
return loaded, nil
}
func defaultPreDump(loaded interface{}) (interface{}, error) {
return loaded, nil
}