-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
38 lines (30 loc) · 948 Bytes
/
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
package main
import (
"fmt"
"os"
"github.com/gin-gonic/gin"
"github.com/joho/godotenv"
"gorm.io/driver/postgres"
"gorm.io/gorm"
"rubenclaessens.nl/kilometerweter-backend/config"
"rubenclaessens.nl/kilometerweter-backend/models"
"rubenclaessens.nl/kilometerweter-backend/routers"
)
func main() {
godotenv.Load()
DB_HOST := os.Getenv("DB_HOST")
DB_USERNAME := os.Getenv("DB_USERNAME")
DB_PASSWORD := os.Getenv("DB_PASSWORD")
DB_NAME := os.Getenv("DB_NAME")
DB_PORT := os.Getenv("DB_PORT")
API_PORT := os.Getenv("API_PORT")
GIN_MODE := os.Getenv("GIN_MODE")
if GIN_MODE == "release" {
gin.SetMode(gin.ReleaseMode)
}
// Connect and migrate database
config.DB, _ = gorm.Open(postgres.Open(fmt.Sprintf("host=%s user=%s password=%s dbname=%s port=%s", DB_HOST, DB_USERNAME, DB_PASSWORD, DB_NAME, DB_PORT)), &gorm.Config{})
config.DB.AutoMigrate(&models.Registration{})
r := routers.SetupRouters()
r.Run(":" + API_PORT)
}