subhub/data/data.go

33 lines
445 B
Go
Raw Permalink Normal View History

2019-09-07 14:54:53 +00:00
package data
import (
"database/sql"
"fmt"
)
var (
pool *sql.DB
)
func GetDB() *sql.DB {
if pool == nil {
// TODO write text
panic("")
}
return pool
}
func NewDB() (*sql.DB, error) {
const (
host = "localhost"
user = "admin"
pass = "Bambukalo2201"
dbname = "subhub"
)
dbConnString := fmt.Sprintf("%s:%s@%s/%s?charset=utf8mb4&parseTime=true",
user, pass, host, dbname)
return sql.Open("mysql", dbConnString)
}