-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
44 lines (34 loc) · 1.08 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
package main
import (
"fmt"
"log"
"os"
"github.com/joho/godotenv"
"github.com/HasnathJami/Food-Nutrition-Go-Fiber-Gorm-Postgres-Docker/database"
"github.com/HasnathJami/Food-Nutrition-Go-Fiber-Gorm-Postgres-Docker/models"
"github.com/HasnathJami/Food-Nutrition-Go-Fiber-Gorm-Postgres-Docker/routers"
"github.com/HasnathJami/Food-Nutrition-Go-Fiber-Gorm-Postgres-Docker/utils"
)
func main() {
err := godotenv.Load(".env")
utils.CheckError(err,"")
config := &models.Config{
Host: os.Getenv("DB_HOST"),
Port: os.Getenv("DB_PORT"),
Password: os.Getenv("DB_PASSWORD"),
User: os.Getenv("DB_USER"),
SSLMode: os.Getenv("DB_SSLMODE"),
DBName: os.Getenv("DB_NAME"),
}
db, err := database.NewConnection(config)
utils.CheckError(err, "Could Not Load The Database")
err = models.MigrateDatabase(db)
utils.CheckError(err, "Could Not Migrate The Database")
// var repository *models.Repository = &models.Repository{
// DB : db,
// }
r := routers.Router()
utils.SetDB(db)
fmt.Println("Starting The Server on Port"+os.Getenv("PORT"))
log.Fatal(r.Listen(":" + os.Getenv("PORT")))
}