Skip to content

Instantly share code, notes, and snippets.

@Develp10
Created April 15, 2022 08:47
Show Gist options
  • Select an option

  • Save Develp10/d0ee2d7911240810fe3c4618d6c29ffd to your computer and use it in GitHub Desktop.

Select an option

Save Develp10/d0ee2d7911240810fe3c4618d6c29ffd to your computer and use it in GitHub Desktop.
package db
import (
"fmt"
"log"
"go-fiber-api-docker/pkg/common/config"
"go-fiber-api-docker/pkg/common/models"
"gorm.io/driver/postgres"
"gorm.io/gorm"
)
func Init(c *config.Config) *gorm.DB {
url := fmt.Sprintf("postgres://%s:%s@%s:%s/%s", c.DBUser, c.DBPass, c.DBHost, c.DBPort, c.DBName)
db, err := gorm.Open(postgres.Open(url), &gorm.Config{})
if err != nil {
log.Fatalln(err)
}
db.AutoMigrate(&models.Product{})
return db
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment