Created
April 15, 2022 08:47
-
-
Save Develp10/d0ee2d7911240810fe3c4618d6c29ffd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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