This repository has been archived by the owner on Aug 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
76 lines (66 loc) · 1.47 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
package main
import (
"log"
"os"
"os/signal"
"sync"
"github.com/alexflint/go-arg"
"github.com/kelseyhightower/envconfig"
"github.com/pilillo/mastro/catalogue"
"github.com/pilillo/mastro/catalogue/crawlers"
"github.com/pilillo/mastro/featurestore"
"github.com/pilillo/mastro/utils/conf"
"github.com/pilillo/mastro/utils/ux"
)
func waitForCtrlC() {
var endWaiter sync.WaitGroup
endWaiter.Add(1)
var signalChannel chan os.Signal
signalChannel = make(chan os.Signal, 1)
signal.Notify(signalChannel, os.Interrupt)
go func() {
<-signalChannel
endWaiter.Done()
}()
endWaiter.Wait()
}
func loadCfg() *conf.Config {
err := envconfig.Process("mastro", &conf.Args)
if err != nil {
log.Printf("Impossible to parse from env vars - %v", err.Error())
log.Printf("Attempting parsing string arguments")
arg.MustParse(&conf.Args)
}
// load config from file
return conf.Load(conf.Args.Config)
}
func start() {
switch Cfg.ConfigType {
case "crawler":
_, err := crawlers.Start(Cfg)
if err != nil {
panic(err.Error())
}
case "catalogue":
catalogue.StartEndpoint(Cfg)
case "featurestore":
featurestore.StartEndpoint(Cfg)
default:
log.Println("Invalid config type", Cfg.ConfigType)
}
}
var (
// Cfg ... global Config
Cfg *conf.Config
)
func main() {
log.Println("Starting")
log.Println(ux.Header)
log.Println(ux.Description)
// load configuration
Cfg = loadCfg()
// start selected service
start()
log.Println("Waiting for Ctrl+C...")
waitForCtrlC()
}