generated from koddr/template-go
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.go
82 lines (73 loc) Β· 1.9 KB
/
app.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package main
import (
"fmt"
"time"
)
// newApp provides a new application instance.
func newApp(config *Config, inputs *Inputs, filtered *Filtered, outputs *Outputs) *App {
return &App{
Config: config,
Inputs: inputs,
Filtered: filtered,
Outputs: outputs,
}
}
// start starts an application with a beauty output to console.
func (app *App) start() error {
// Start timer.
start := time.Now()
// Check, if input data is not empty.
if app.Inputs.Data != nil {
if len(app.Inputs.Data) > 0 {
printStyled(
"Hello and welcome to csv2api! π",
"margin-top-bottom",
)
printStyled(
fmt.Sprintf(
"β According to the settings in '%s', %d transactions were filtered out of %d to start the process.",
configFilePath, len(app.Filtered.Data), len(app.Inputs.Data),
),
"",
)
// Check, if output data is not empty.
if len(app.Outputs.Data) > 0 {
printStyled(
fmt.Sprintf(
"β Only %d transactions got into the final set of actions to be taken... Please wait!",
len(app.Outputs.Data),
),
"margin-bottom",
)
// Loop for all output data.
for _, data := range app.Outputs.Data {
// Start updating fields.
if err := app.updateField(data.ID, data.FieldName, data.Values); err != nil {
printStyled(
fmt.Sprintf("β There was an error with collect output data: %v", err),
"margin-left",
)
}
}
// Check, if you need to save CSV file with filtered PK.
if app.Config.SaveFilteredPKToCSV {
// Save filtered PK to CSV.
if err := app.saveFilteredPKToCSV(); err != nil {
printStyled(
fmt.Sprintf("β There was an error with save filtered PK to CSV: %v", err),
"margin-top",
)
}
}
}
}
printStyled(
fmt.Sprintf(
"All done! π Time elapsed: %.2fs",
time.Since(start).Seconds(),
),
"margin-top-bottom",
)
}
return nil
}