You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

19 lines
581 B

  1. package init
  2. import (
  3. "gin-vue-admin/global"
  4. "github.com/jinzhu/gorm"
  5. _ "github.com/jinzhu/gorm/dialects/mysql"
  6. )
  7. //初始化数据库并产生数据库全局变量
  8. func RegisterMysql(admin MysqlAdmin) {
  9. if db, err := gorm.Open("mysql", admin.Username+":"+admin.Password+"@("+admin.Path+")/"+admin.Dbname+"?"+admin.Config); err != nil {
  10. L.Error("DEFAULTDB数据库启动异常", err)
  11. } else {
  12. global.GVA_DB = db
  13. global.GVA_DB.DB().SetMaxIdleConns(admin.MaxIdleConns)
  14. global.GVA_DB.DB().SetMaxOpenConns(admin.MaxOpenConns)
  15. global.GVA_DB.LogMode(admin.LogMode)
  16. }
  17. }