Browse Source

JWT Authorization

user
Seyora24 1 year ago
parent
commit
c8a675d1d0
  1. 5
      initializers/database.go
  2. 7
      initializers/syncDatabase.go

5
initializers/database.go

@ -1,7 +1,6 @@
package initializers
import (
"log"
"os"
"gorm.io/driver/postgres"
@ -12,10 +11,10 @@ var DB *gorm.DB
func ConnectToDB() {
var err error
dsn := os.Getenv("DB_URL")
dsn := os.Getenv("DB")
DB, err = gorm.Open(postgres.Open(dsn), &gorm.Config{})
if err != nil {
log.Fatal("Failed to connect to database")
panic("Failed to connect to database")
}
}

7
initializers/syncDatabase.go

@ -0,0 +1,7 @@
package initializers
import "tugas1/models"
func SyncDatabase() {
DB.AutoMigrate(&models.Post{})
}
Loading…
Cancel
Save