Fix all compilation errors related to ers after making ees opts of type struct

This commit is contained in:
ionutboangiu
2021-11-25 17:20:33 +02:00
committed by Dan Christian Bogos
parent aa0ae292a2
commit 40eb832060
27 changed files with 355 additions and 459 deletions

View File

@@ -71,18 +71,18 @@ func (sqlEe *SQLEe) initDialector() (err error) {
password, _ := u.User.Password()
dbname := utils.SQLDefaultDBName
if vals, has := sqlEe.Cfg().Opts[utils.SQLDBNameOpt]; has {
dbname = utils.IfaceAsString(vals)
if sqlEe.Cfg().Opts.SQLDBName != nil {
dbname = *sqlEe.Cfg().Opts.SQLDBName
}
ssl := utils.SQLDefaultSSLMode
if vals, has := sqlEe.Cfg().Opts[utils.SSLModeCfg]; has {
ssl = utils.IfaceAsString(vals)
if sqlEe.Cfg().Opts.SSLMode != nil {
ssl = *sqlEe.Cfg().Opts.SSLMode
}
// tableName is mandatory in opts
if iface, has := sqlEe.Cfg().Opts[utils.SQLTableNameOpt]; !has {
return utils.NewErrMandatoryIeMissing(utils.SQLTableNameOpt)
if sqlEe.Cfg().Opts.SQLTableName != nil {
sqlEe.tableName = *sqlEe.Cfg().Opts.SQLTableName
} else {
sqlEe.tableName = utils.IfaceAsString(iface)
return utils.NewErrMandatoryIeMissing(utils.SQLTableNameOpt)
}
// var dialect gorm.Dialector
@@ -98,7 +98,7 @@ func (sqlEe *SQLEe) initDialector() (err error) {
return
}
func openDB(dialect gorm.Dialector, opts map[string]interface{}) (db *gorm.DB, sqlDB *sql.DB, err error) {
func openDB(dialect gorm.Dialector, opts *config.EventExporterOpts) (db *gorm.DB, sqlDB *sql.DB, err error) {
if db, err = gorm.Open(dialect, &gorm.Config{AllowGlobalUpdate: true}); err != nil {
return
}
@@ -106,26 +106,14 @@ func openDB(dialect gorm.Dialector, opts map[string]interface{}) (db *gorm.DB, s
return
}
if iface, has := opts[utils.SQLMaxIdleConnsCfg]; has {
val, err := utils.IfaceAsTInt64(iface)
if err != nil {
return nil, nil, err
}
sqlDB.SetMaxIdleConns(int(val))
if opts.SQLMaxIdleConns != nil {
sqlDB.SetMaxIdleConns(*opts.SQLMaxIdleConns)
}
if iface, has := opts[utils.SQLMaxOpenConns]; has {
val, err := utils.IfaceAsTInt64(iface)
if err != nil {
return nil, nil, err
}
sqlDB.SetMaxOpenConns(int(val))
if opts.SQLMaxOpenConns != nil {
sqlDB.SetMaxOpenConns(*opts.SQLMaxOpenConns)
}
if iface, has := opts[utils.SQLConnMaxLifetime]; has {
val, err := utils.IfaceAsDuration(iface)
if err != nil {
return nil, nil, err
}
sqlDB.SetConnMaxLifetime(val)
if opts.SQLConnMaxLifetime != nil {
sqlDB.SetConnMaxLifetime(*opts.SQLConnMaxLifetime)
}
return