2019-11-10 08:42:49 +00:00
|
|
|
package mysql
|
|
|
|
|
|
|
|
import (
|
2020-04-29 15:02:09 +00:00
|
|
|
"code.hoteas.com/golang/hotime"
|
2019-11-10 08:42:49 +00:00
|
|
|
"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
|
|
|
|
})
|
|
|
|
}
|