milvus init
This commit is contained in:
@@ -9,23 +9,17 @@ import (
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
)
|
||||
|
||||
// 初始化数据库连接
|
||||
//func (m *MysqlConnectionx) Init() {
|
||||
// fmt.Println("初始化数据库连接")
|
||||
//}
|
||||
|
||||
type MysqlConnection struct {
|
||||
Database *sql.DB
|
||||
}
|
||||
|
||||
// 初始化数据库连接
|
||||
func (m *MysqlConnection) Init() (err error) {
|
||||
viper := Viper // 从 models/config.go 中获取 viper 对象
|
||||
user := viper.Get("mysql.user").(string)
|
||||
password := viper.Get("mysql.password").(string)
|
||||
host := viper.Get("mysql.host").(string)
|
||||
port := viper.Get("mysql.port").(int)
|
||||
database := viper.Get("mysql.database").(string)
|
||||
user := Viper.Get("mysql.user").(string)
|
||||
password := Viper.Get("mysql.password").(string)
|
||||
host := Viper.Get("mysql.host").(string)
|
||||
port := Viper.Get("mysql.port").(int)
|
||||
database := Viper.Get("mysql.database").(string)
|
||||
sqlconf := user + ":" + password + "@tcp(" + host + ":" + strconv.Itoa(port) + ")/" + database + "?charset=utf8mb4&parseTime=True&loc=Local"
|
||||
m.Database, err = sql.Open("mysql", sqlconf) // 连接数据库
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user