-
Notifications
You must be signed in to change notification settings - Fork 2
/
result.go
61 lines (53 loc) · 1.47 KB
/
result.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
55
56
57
58
59
60
61
package mongoimport
import (
"fmt"
"path/filepath"
"time"
)
// LoggableResult ...
type LoggableResult interface {
Summary() string
}
// ImportResult ...
type ImportResult struct {
TotalFiles int
TotalSources int
Description string
Succeeded int
Failed int
Elapsed time.Duration
PartialResults []SourceResult
}
// Summary ...
func (ir ImportResult) Summary() string {
return fmt.Sprintf("[TOTAL]: %d rows from %d sources (%d files) were imported successfully and %d failed in %s", ir.Succeeded, ir.TotalSources, ir.TotalFiles, ir.Failed, ir.Elapsed)
}
// SourceResult ...
type SourceResult struct {
TotalFiles int
Collection string
Description string
Succeeded int
Failed int
Elapsed time.Duration
PartialResults []PartialResult
}
// Summary ...
func (ir SourceResult) Summary() string {
return fmt.Sprintf("[%s -> %s]: %d rows from %d files were imported successfully and %d failed in %s", ir.Description, ir.Collection, ir.Succeeded, ir.TotalFiles, ir.Failed, ir.Elapsed)
}
// PartialResult ...
type PartialResult struct {
File string
Collection string
Source *Datasource
Succeeded int
Failed int
Elapsed time.Duration
Errors []error
}
// Summary ...
func (ir PartialResult) Summary() string {
filename := filepath.Base(ir.File)
return fmt.Sprintf("[%s -> %s]: %d rows were imported successfully and %d failed in %s", filename, ir.Collection, ir.Succeeded, ir.Failed, ir.Elapsed)
}