-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
51 lines (42 loc) · 1.32 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
package main
import (
flag "github.com/ogier/pflag"
"github.com/sirupsen/logrus"
"github.com/Depado/assistant-codelabs/conf"
"github.com/Depado/assistant-codelabs/database"
"github.com/Depado/assistant-codelabs/router"
"github.com/Depado/assistant-codelabs/utils"
)
func main() {
var err error
var csvf, cnff string
var expf bool
flag.StringVarP(&csvf, "import", "i", "", "CSV file to import in the database")
flag.BoolVarP(&expf, "export", "e", false, "Exports brands, models and such")
flag.StringVarP(&cnff, "conf", "c", "conf.yml", "Configuration file to import")
flag.Parse()
// Load configuration file
if err = conf.Load(cnff); err != nil {
logrus.WithError(err).Fatal("Couldn't load configuration file")
}
logrus.WithFields(logrus.Fields{"conf": cnff, "listen": conf.C.ListenAddress()}).Info("Parsed configuration file")
// Initialize the database
if err = database.Init(); err != nil {
logrus.WithError(err).Fatal("Couldn't intialize database")
}
// Export action
if expf {
if err = utils.ExportAll(); err != nil {
logrus.WithError(err).Fatal("Couldn't export")
}
return
}
// Import if needed
if csvf != "" {
if err = utils.ImportFromFile(csvf); err != nil {
logrus.WithError(err).Fatal("Couldn't import file")
}
}
// Run the router and start accepting incoming requests
router.Run()
}