-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
72 lines (55 loc) · 1.73 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
package main
import (
"myapp/src/cassandra"
"myapp/src/config"
logs "myapp/src/log"
"myapp/src/postgres"
"myapp/src/redis"
"myapp/src/server"
)
func main() {
cfg,err := config.LoadConfig()
if err != nil {
panic(err)
}
logger := logs.NewLogger(cfg.Log)
logger.Info().Msgf("Config %v", cfg)
pgConn, err := postgres.NewPostgresConnection(cfg.Postgres, logger)
if err != nil {
logger.Fatal().Err(err).Msg("Failed to connect to database")
}
defer pgConn.Close()
if cfg.Postgres.Migrations.Enabled {
logger.Info().Msg("Running postgres migrations")
if err := postgres.Migrate(pgConn, cfg.Postgres.Migrations.Path); err != nil {
logger.Fatal().Err(err).Msg("Failed to run postgres migrations")
}
logger.Info().Msg("Database migrations completed successfully")
}
cassandraClient,err := cassandra.NewCassandraConnection(cfg.Cassandra,logger)
if err!=nil{
logger.Fatal().Err(err).Msg("Failed to connect to cassandra")
}
defer cassandraClient.Close()
if cfg.Cassandra.Migrations.Enabled {
err:=cassandra.Migrate(cassandraClient,logger, cfg.Cassandra.Migrations.Path, cfg.Cassandra.Keyspace)
if err!=nil{
logger.Fatal().Err(err).Msg("Failed to run cassandra migrations")
// logger.Error().Err(err)
}
}
redisClient,err := redis.NewRedisClient(cfg.Redis, logger)
if err != nil {
logger.Fatal().Err(err).Msg("Failed to connect to Redis")
}
defer redisClient.Close()
app := &config.App{
Config: cfg,
Logger: logger,
Postgres: pgConn,
Redis: redisClient,
Cassandra: cassandraClient,
}
srv := server.NewServer(app)
srv.Start()
}