-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
66 lines (50 loc) · 1.33 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
package main
import (
"fmt"
"iqraa-api/domain"
"iqraa-api/handlers"
"iqraa-api/postgres"
"iqraa-api/redis"
"log"
"net/http"
"os"
"github.com/joho/godotenv"
)
func main() {
// Load the .env file in the current directory
godotenv.Load()
// or
//godotenv.Load(".env")
// Connet to Postgres DB
DB := postgres.ConnectPostgres(os.Getenv("DB_URI"))
defer DB.Close()
err := postgres.TestDBConnection(DB)
if err != nil {
fmt.Println(err)
}
/* in case of having no dump - this was for creating DB tables using models */
// err = postgres.RecreateSchema(DB)
// if err != nil {
// fmt.Println(err)
// }
domainDB := domain.DB{
UserRepo: postgres.NewUserRepo(DB),
BookRepo: postgres.NewBookRepo(DB),
AuthorRepo: postgres.NewAuthorRepo(DB),
ReviewRepo: postgres.NewReviewRepo(DB),
QuoteRepo: postgres.NewQuoteRepo(DB),
StatisticsRepo: postgres.NewStatisticsRepo(DB),
}
// Connect to Redis DB
redisDB := redis.ConnectRedis(os.Getenv("REDIS_DB_URI"))
defer redisDB.Close()
domainRedisDB := domain.RedisDB{
RedisStringsRepo: redis.NewRedisStringsRepo(redisDB),
}
d := &domain.Domain{DB: domainDB, RedisDB: domainRedisDB}
r := handlers.SetupRouter(d)
err = http.ListenAndServe(fmt.Sprintf(":%s", os.Getenv("PORT")), r)
if err != nil {
log.Fatalf("cannot start server %v", err)
}
}