-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
51 lines (42 loc) · 1.04 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 (
"os"
"github.com/dhurimkelmendi/vending_machine/config"
"github.com/dhurimkelmendi/vending_machine/db"
"github.com/dhurimkelmendi/vending_machine/migrations"
"github.com/dhurimkelmendi/vending_machine/server"
"github.com/sirupsen/logrus"
)
func main() {
logrus.Infof("Server starting ...")
if len(os.Args) > 1 {
action := os.Args[1]
if action == "migrate" {
if len(os.Args) > 2 {
migrate(os.Args[2])
} else {
logrus.Fatal("Missing migration action.")
}
} else {
logrus.Fatalf("Unknown action: %s", action)
}
} else {
run()
}
}
func run() {
config.GetDefaultInstance().SetLogLevel()
config.GetDefaultInstance().LogConfigs()
server.GetDefaultInstance().Start()
}
func migrate(action string) {
logrus.Infof("Starting migration -- action: %s", action)
config.GetDefaultInstance().SetLogLevel()
config.GetDefaultInstance().LogConfigs()
dbConn := db.GetDefaultInstance()
if action == "reset" {
migrations.Reset(dbConn.GetDB())
} else {
migrations.Migrate(action, dbConn.GetDB())
}
}