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.

20 lines
610 B

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