package global import ( "fmt" "gorm.io/driver/mysql" "gorm.io/gorm" "gorm.io/gorm/logger" ) var ( DBLink *gorm.DB ) func SetupDBLink() error { var err error dsn := fmt.Sprintf("%s:%s@tcp(%s)/%s?%s", DatabaseSetting.UserName, DatabaseSetting.Password, DatabaseSetting.Host, DatabaseSetting.Db, DatabaseSetting.OtherParams, ) DBLink, err = gorm.Open(mysql.Open(dsn), &gorm.Config{ DisableForeignKeyConstraintWhenMigrating: true, Logger: logger.Default.LogMode(logger.Info), }) if err != nil { return err } //DBLink.SingularTable(true) //DBLink.DB().SetMaxIdleConns(DatabaseSetting.MaxIdleConn) //DBLink.DB().SetMaxOpenConns(DatabaseSetting.MaxOpenConn) return nil }