1
0
mirror of https://github.com/JustKato/FreePad.git synced 2026-02-24 00:00:46 +02:00

* Corrections

This commit is contained in:
2022-05-15 15:21:21 +03:00
parent 21b8605fc0
commit e508d753ce
6 changed files with 48 additions and 3 deletions

View File

@@ -0,0 +1,30 @@
package database
import (
"database/sql"
"fmt"
"os"
"time"
_ "github.com/go-sql-driver/mysql"
)
func GetConn() *sql.DB {
user := os.Getenv("MYSQL_USER")
password := os.Getenv("MYSQL_PASSWORD")
dbname := os.Getenv("MYSQL_DATABASE")
db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@/%s", user, password, dbname))
if err != nil {
panic(err)
}
// Set options
db.SetConnMaxLifetime(time.Minute * 5)
db.SetMaxOpenConns(10)
db.SetMaxIdleConns(10)
return db
}