added connection string to config

This commit is contained in:
2021-11-04 20:28:37 +01:00
parent 9be7b6c18f
commit 8725def3a1
5 changed files with 11 additions and 9 deletions

View File

@@ -19,18 +19,16 @@ type DB struct {
dbConn *sql.DB
}
func NewDB(driver, dataSourceName string) (*DB, error) {
db, err := sql.Open(driver, dataSourceName)
func NewDB(dataSourceName string) (*DB, error) {
db, err := sql.Open("mysql", dataSourceName)
if err != nil {
return nil, err
}
if driver == "mysql" {
db.SetConnMaxLifetime(time.Minute * 3)
db.SetMaxOpenConns(10)
db.SetMaxIdleConns(10)
}
db.SetConnMaxLifetime(time.Minute * 3)
db.SetMaxOpenConns(10)
db.SetMaxIdleConns(10)
return &DB{
dbConn: db,

View File

@@ -54,7 +54,7 @@ func Start(config types.AppConfig) {
return
}
dbStore, err := db.NewDB("mysql", "s3Browser:hunter2@/s3Browser")
dbStore, err := db.NewDB(config.DSN)
if err != nil {
log.Error("Failed to connect DB: ", err.Error())
}

View File

@@ -13,6 +13,7 @@ type AppConfig struct {
S3SecretKey string
S3SSL bool
S3Bucket string
DSN string
CacheTTL time.Duration
CacheCleanup time.Duration
Address string