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.

22 lines
617 B

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