-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
61 lines (52 loc) · 1.43 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
package main
import (
"log"
"os"
"strings"
"github.com/kelseyhightower/envconfig"
"github.com/litmuschaos/litmus/litmus-portal/upgrader-agents/control-plane/pkg/database"
"github.com/litmuschaos/litmus/litmus-portal/upgrader-agents/control-plane/versions"
"go.uber.org/zap"
)
type Config struct {
Version string `required:"true"`
DbServer string `required:"true" split_words:"true"`
DbUser string `required:"true" split_words:"true"`
DbPassword string `required:"true" split_words:"true"`
}
func init() {
var c Config
err := envconfig.Process("", &c)
if err != nil {
log.Fatal(err)
}
}
func main() {
// logging level, dev mode enables debug logs
dev := os.Getenv("DEV_MODE")
var logger *zap.Logger
var err error
// set log level
if strings.ToLower(dev) == "true" {
logger, err = zap.NewDevelopment()
} else {
logger, err = zap.NewProduction()
}
if err != nil {
log.Fatal("failed to create logger")
}
// create database connection
dbClient, err := database.Connect()
if err != nil {
logger.Fatal("failed to get db client", zap.Error(err))
}
// create new upgrade manager
mg, err := versions.NewUpgradeManager(logger, dbClient)
if err != nil {
logger.Fatal("failed to create upgrade manager", zap.Error(err))
}
// execute upgrade manager
if err = mg.Run(); err != nil {
logger.Fatal("failed to run upgrade manager", zap.Error(err))
}
}