forked from golang/hotime
20 lines
562 B
Go
20 lines
562 B
Go
|
package mysql
|
||
|
|
||
|
import (
|
||
|
"code.hoteas.com/golang/hotime"
|
||
|
"database/sql"
|
||
|
_ "github.com/go-sql-driver/mysql"
|
||
|
)
|
||
|
|
||
|
func SetDB(appIns *hotime.Application) {
|
||
|
appIns.SetConnectDB(func(err ...*hotime.Error) *sql.DB {
|
||
|
query := appIns.Config.GetString("dbUser") + ":" + appIns.Config.GetString("dbPwd") +
|
||
|
"@tcp(" + appIns.Config.GetString("dbHost") + ":" + appIns.Config.GetString("dbPort") + ")/" + appIns.Config.GetString("dbName") + "?charset=utf8"
|
||
|
DB, e := sql.Open("mysql", query)
|
||
|
if e != nil && len(err) != 0 {
|
||
|
err[0].SetError(e)
|
||
|
}
|
||
|
return DB
|
||
|
})
|
||
|
}
|