-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
79 lines (71 loc) · 1.53 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package main
import (
"flag"
"fmt"
"log"
"os"
"os/signal"
"syscall"
"github.com/joho/godotenv"
)
func main() {
Singleton("127.0.0.1:51337")
log.Printf("⬅🖐 leftshove started")
CtrlC()
var confFile string
flag.StringVar(&confFile, "config", "./sample.env", "configuration .env file location (ie. './config.env')")
seedFlag := flag.Bool("seed", false, "seed nms db")
cdcFlag := flag.Bool("cdc", false, "seed nms db")
runOnce := flag.Bool("runonce", false, "run and capture source only once")
bqGenFlag := flag.Bool("bq", false, "generate bigquery table schemas")
flag.Parse()
err := godotenv.Load(confFile)
if err != nil {
log.Fatal("error loading .env file")
}
if *seedFlag {
fmt.Printf("seed nms db: %v\n", *seedFlag)
err := seedNMSdb()
if err != nil {
log.Println(err)
os.Exit(1)
}
}
if *bqGenFlag {
err := createBQtables()
if err != nil {
log.Println(err)
// os.Exit(2)
}
}
if *cdcFlag {
fmt.Printf("cdc: %v\n", *cdcFlag)
if *runOnce {
err := cdc()
if err != nil {
log.Println(err)
os.Exit(3)
}
} else {
for {
err := cdc()
if err != nil {
log.Println(err)
os.Exit(4)
}
}
}
}
log.Printf("End")
}
// CtrlC intercepts any Ctrl+C keyboard input and exits to the shell.
func CtrlC() {
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
go func() {
<-c
log.Printf("End")
fmt.Fprintf(os.Stdout, " ⬅🖐 👋\n")
os.Exit(5)
}()
}