package db import ( "github.com/1Panel-dev/1Panel/global" "gorm.io/driver/mysql" "gorm.io/gorm" ) func MysqlGorm() *gorm.DB { m := global.CONF.Mysql if m.Dbname == "" { return nil } mysqlConfig := mysql.Config{ DSN: m.Dsn(), DefaultStringSize: 191, SkipInitializeWithVersion: false, } if db, err := gorm.Open(mysql.New(mysqlConfig), &gorm.Config{}); err != nil { panic(err) } else { sqlDB, _ := db.DB() sqlDB.SetMaxIdleConns(m.MaxIdleConns) sqlDB.SetMaxOpenConns(m.MaxOpenConns) return db } }