代码拉取完成,页面将自动刷新
// Copyright (c) 2020 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
/**
*@describe:
*@author wfl19/Kristas
*@date 2021/04/10
*/
package datasource_processor
import (
"database/sql"
"fmt"
"gitee.com/kristas/booting-go/framework/data"
"github.com/go-sql-driver/mysql"
"time"
)
func init() {
UseDataBaseHandler("mysql", mysqlHandler)
}
func mysqlHandler(d *DatasourceProcessor, config data.Datasource) *sql.DB {
switch config.GetTunnel() {
case "ssh":
mysql.RegisterDialContext("mysql+ssh", d.sshDialer.Dial)
case "tcp":
mysql.RegisterDialContext("mysql+tcp", d.tcpDialer.Dial)
}
dsn := fmt.Sprintf("%s:%s@mysql+%s(%s)%s",
config.GetUsername(), config.GetPassword(), config.GetTunnel(), config.GetHost(), config.GetDatabase())
conn, err := sql.Open("mysql", dsn)
if err != nil {
d.Log.Panic("Failed to open mysql connection:\ncaused by:\ndsn: %s\n%s", dsn, err.Error())
}
if !config.IsLazyFetch() {
if err = conn.Ping(); err != nil {
d.Log.Panic("ping mysql failed:\ncaused by:\n%s", err.Error())
}
}
initConn(config, conn)
return conn
}
func initConn(config data.Datasource, conn *sql.DB) {
if config.GetConnMaxLifeTime() != 0 {
conn.SetConnMaxLifetime(time.Second * time.Duration(config.GetConnMaxLifeTime()))
}
if config.GetConnMaxIdleTime() != 0 {
conn.SetConnMaxIdleTime(time.Second * time.Duration(config.GetConnMaxIdleTime()))
}
if config.GetMaxIdleConns() != 0 {
conn.SetMaxIdleConns(config.GetMaxIdleConns())
}
if config.GetMaxOpenConns() != 0 {
conn.SetMaxOpenConns(config.GetMaxOpenConns())
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。