-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
82 lines (68 loc) · 1.77 KB
/
Copy pathmain.go
File metadata and controls
82 lines (68 loc) · 1.77 KB
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"
"flag"
"github.com/dmitry-udod/codes_go/app/router"
"github.com/dmitry-udod/codes_go/app/services"
"github.com/dmitry-udod/codes_go/cmd"
. "github.com/dmitry-udod/codes_go/logger"
"os"
)
var importFop = flag.String("import-fop", "", "Import FOPs from file")
var importLegalEntity = flag.String("import-legal-entity", "", "Import legal entities from file")
var importTerrorists = flag.String("import-terrorist", "", "Import terrorist list from file")
var generateSiteMap = flag.String("generate-site-map", "", "Generate sitemap files from file")
func main() {
flag.Parse()
InitLogger()
services.InitElasticSearchClient()
if ! isCliCommand() {
r := router.SetupRouter()
r.Run()
}
}
func isCliCommand() bool {
if len(os.Args) < 2 {
return false
}
filePath := os.Args[2]
if _, err := os.Stat(filePath); os.IsNotExist(err) {
msg := fmt.Sprintf("File %s NOT found", filePath)
fmt.Println(msg)
Log.Fatal(msg);
}
file, err := os.Open(filePath)
if err != nil {
Log.Fatal(err)
}
defer file.Close()
Log.Info("Start processing file: " + filePath);
if *importFop != "" {
Log.Info("Run import FOP command")
cmd.ImportFop(file)
finishFileProcess(filePath)
return true
}
if *importLegalEntity != "" {
Log.Info("Run import legal entity command")
cmd.ImportLegalEntity(file)
finishFileProcess(filePath)
return true
}
if *importTerrorists != "" {
Log.Info("Run import terrorists command")
cmd.ImportTerrorist(file)
finishFileProcess(filePath)
return true
}
if *generateSiteMap != "" {
Log.Info("Start site map generation")
cmd.GenerateSiteMap(file)
Log.Info("Finish site map generation")
return true
}
return false
}
func finishFileProcess(filePath string) {
Log.Info("Finish processing file: " + filePath);
}