moved mysql connection pool config to openConection func

This commit is contained in:
Yosyp Buchma 2023-09-20 13:13:50 +03:00
parent f472becd89
commit dd8d043cb8
2 changed files with 5 additions and 4 deletions

View file

@ -12,6 +12,8 @@ import (
mysqldr "github.com/go-sql-driver/mysql"
)
const mysqlMaxConns = 10
// DBConnection contains MySQL connection details
type DBConnection struct {
Host string
@ -83,6 +85,9 @@ func openConnection(connectionString string) (*sql.DB, error) {
return nil, fmt.Errorf("failed to open mysql connection: %w", err)
}
db.SetMaxOpenConns(mysqlMaxConns)
db.SetMaxIdleConns(mysqlMaxConns)
err = db.Ping()
if err != nil {
return nil, fmt.Errorf("failed to ping database: %w", err)