generated from koddr/template-go
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
61 lines (54 loc) Β· 1.58 KB
/
main.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 main
import (
"flag"
"fmt"
"os"
"path/filepath"
)
func main() {
// Listen to flags.
flag.BoolVar(&initConfig, "i", false, "set to generate initial config and example data files")
flag.StringVar(&configFilePath, "c", "", "set path to your config file")
flag.StringVar(&inputDataFilePath, "d", "", "set path to your CSV file with input data")
flag.StringVar(&envPrefix, "e", "CONFIG", "set prefix used in your environment variables")
// Parse all given flags.
flag.Parse()
// If '-i' flag is true, generates config and example data files.
if initConfig {
// Create the config file in the current dir.
if err := os.WriteFile(filepath.Clean("./config.yml"), embedConfigYAMLFile, 0o600); err != nil {
printStyled(
fmt.Sprintf("β There was an error with generate config.yml file: %v", err),
"",
)
}
// Create the example data file in the current dir.
if err := os.WriteFile(filepath.Clean("./data.csv"), embedDataCSVFile, 0o600); err != nil {
printStyled(
fmt.Sprintf("β There was an error with generate data.csv file: %v", err),
"",
)
}
// Show success message.
printStyled(
"The configuration and example data files was successfully generated in the current dir!",
"margin-top-bottom",
)
} else {
// App initialization.
app, err := initialize()
if err != nil {
printStyled(
fmt.Sprintf("β There was an error with initialize app: %v", err),
"",
)
}
// App start.
if err = app.start(); err != nil {
printStyled(
fmt.Sprintf("β There was an error with starting app: %v", err),
"",
)
}
}
}