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(), )) } return dbx }