db.go 305 B

12345678910111213141516
  1. package main
  2. import (
  3. "gorm.io/driver/mysql"
  4. "gorm.io/gorm"
  5. "log"
  6. )
  7. func InitializeGorm(config MySQLConfig) (*gorm.DB, error) {
  8. db, err := gorm.Open(mysql.Open(config.DSN()), &gorm.Config{})
  9. if err != nil {
  10. log.Printf("failed to connect database: %v", err)
  11. return nil, err
  12. }
  13. return db, nil
  14. }