讨论数量:
我这 gin 框架 func NewDBEngine (databaseSetting setting.DatabaseSettingS) (gorm.DB, error) { s := "%s:%s@tcp(%s)/%s?charset=%s&parseTime=%t&loc=Local" db, err := gorm.Open(databaseSetting.DBType, fmt.Sprintf(s, databaseSetting.UserName, databaseSetting.Password, databaseSetting.Host, databaseSetting.DBName, databaseSetting.Charset, databaseSetting.ParseTime, ))
if err != nil {
fmt.Println(err)
return nil, err
}
if global.ServerSetting.RunMode == "debug" {
db.LogMode(true)
}
db.SingularTable(true)
db.DB().SetMaxIdleConns(databaseSetting.MaxIdleConns)
db.DB().SetMaxOpenConns(databaseSetting.MaxOpenConns)
return db, nil
} 这样还是不行 runtime error: invalid memory address or nil pointer dereference
推荐文章: