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.
25 lines
530 B
25 lines
530 B
package database
|
|
|
|
import (
|
|
"database/sql"
|
|
"fmt"
|
|
_ "github.com/go-sql-driver/mysql"
|
|
"github.com/taoshihan1991/imaptool/config"
|
|
)
|
|
type Mysql struct{
|
|
SqlDB *sql.DB
|
|
Dsn string
|
|
}
|
|
func NewMysql()*Mysql{
|
|
mysql:=config.CreateMysql()
|
|
dsn := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8&parseTime=True&loc=Local", mysql.Username, mysql.Password, mysql.Server, mysql.Port, mysql.Database)
|
|
return &Mysql{
|
|
Dsn:dsn,
|
|
}
|
|
}
|
|
|
|
func (db *Mysql)Ping()error{
|
|
sqlDb, _ := sql.Open("mysql", db.Dsn)
|
|
db.SqlDB=sqlDb
|
|
return db.SqlDB.Ping()
|
|
} |