You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
476 B
32 lines
476 B
package config
|
|
|
|
import (
|
|
"fmt"
|
|
_ "github.com/go-sql-driver/mysql"
|
|
"github.com/jmoiron/sqlx"
|
|
"sync"
|
|
)
|
|
|
|
var dbx *sqlx.DB
|
|
var dbLock sync.Mutex
|
|
|
|
func DBX() *sqlx.DB {
|
|
dbLock.Lock()
|
|
defer dbLock.Unlock()
|
|
|
|
if dbx == nil {
|
|
dbx = sqlx.MustConnect("mysql", fmt.Sprintf(
|
|
"%s:%s@(%s:%d)/%s?parseTime=true",
|
|
MySqlUsername(),
|
|
MySQlPassword(),
|
|
MySqlHost(),
|
|
MySqlPort(),
|
|
MySqlSchema(),
|
|
))
|
|
|
|
dbx.SetMaxIdleConns(50)
|
|
dbx.SetMaxOpenConns(100)
|
|
}
|
|
|
|
return dbx
|
|
}
|