diff --git a/common/database/conn.go b/common/database/conn.go index ffdd332d2b9977f815b10e064abd9e6ae2e4f523..1a57a29acfcd22741fd82782c1f9a493169ddf80 100644 --- a/common/database/conn.go +++ b/common/database/conn.go @@ -58,7 +58,6 @@ func InitTable() error { if err != nil { Tx.Rollback() log.Error("InitTable error:",err,"\t sql:",sql) - panic(err) return err } } diff --git a/server/dao/console-sqlite3/api.go b/server/dao/console-sqlite3/api.go index 6a8cbb67aa7c7f38769dac026a16c7351be20ff5..aebfdb013623e17c04ee98afa342b901ed125d4e 100644 --- a/server/dao/console-sqlite3/api.go +++ b/server/dao/console-sqlite3/api.go @@ -356,6 +356,7 @@ func BatchEditAPIBalance(apiIDList []string, balance string) (string, error) { if err != nil { return "[ERROR]Fail to Prepare SQL!", err } + defer stmt.Close() _, err = stmt.Exec(now, now, balance) if err != nil { return "[ERROR]Fail to excute SQL statement!", err @@ -375,6 +376,7 @@ func BatchEditAPIGroup(apiIDList []string, groupID int) (string, error) { if err != nil { return "[ERROR]Fail to Prepare SQL!", err } + defer stmt.Close() _, err = stmt.Exec(now, now, groupID) if err != nil { return "[ERROR]Fail to excute SQL statement!", err diff --git a/server/dao/console-sqlite3/apiStrategy.go b/server/dao/console-sqlite3/apiStrategy.go index 3b9798f758dc21985d34ac8f673031d66898375f..c85a74c5e5a312f624940068b5fdf4d1a5478c03 100644 --- a/server/dao/console-sqlite3/apiStrategy.go +++ b/server/dao/console-sqlite3/apiStrategy.go @@ -20,6 +20,9 @@ func AddAPIToStrategy(apiList []string, strategyID string) (bool, string, error) stmt1, _ := Tx.Prepare(sql1) stmt2, _ := Tx.Prepare(sql2) stmt3, _ := Tx.Prepare(sql3) + defer stmt1.Close() + defer stmt2.Close() + defer stmt3.Close() for _, apiID := range apiList { id, err := strconv.Atoi(apiID) @@ -64,7 +67,7 @@ func SetAPITargetOfStrategy(apiID int, strategyID string, target string) (bool, if err != nil { return false, err.Error(), err } - + defer stmt.Close() _, e := stmt.Exec(target, apiID, strategyID) if e != nil { @@ -93,7 +96,7 @@ func BatchSetAPITargetOfStrategy(apiIds []int, strategyID string, target string) if err != nil { return false, err.Error(), err } - + defer stmt.Close() _, e := stmt.Exec(s...) if e != nil { diff --git a/server/dao/console-sqlite3/config-log/log.go b/server/dao/console-sqlite3/config-log/log.go index 15f0ccc420a46d287dca80330cb0617ef949f11e..805517a697e01b6b970996cde538593c07489b53 100644 --- a/server/dao/console-sqlite3/config-log/log.go +++ b/server/dao/console-sqlite3/config-log/log.go @@ -14,6 +14,7 @@ func Get(name string) (*entity.LogConfig, error) { if e != nil { return nil, e } + defer stmt.Close() ent := &entity.LogConfig{} err := stmt.QueryRow(name).Scan( &ent.Name, @@ -37,6 +38,7 @@ func Set(ent *entity.LogConfig) error { if e != nil { return e } + defer stmt.Close() _, err := stmt.Exec( ent.Name, ent.Enable, diff --git a/server/dao/console-sqlite3/dao-balance/add.go b/server/dao/console-sqlite3/dao-balance/add.go index 57abc93fd043c36ea502b33e120e200e16f09126..2c07e8191a58812447ee5908dc0e151d9d9c4985 100644 --- a/server/dao/console-sqlite3/dao-balance/add.go +++ b/server/dao/console-sqlite3/dao-balance/add.go @@ -115,6 +115,7 @@ func Delete(name string) (string, error) { if err != nil { return "[ERROR]Illegal SQL statement!", err } + defer stmt.Close() _, err = stmt.Exec(name) if err != nil { return "[ERROR]DELETE fail", err @@ -132,10 +133,12 @@ func BatchDelete(balanceNames []string) (string, error) { if err != nil { return "[ERROR]Illegal SQL statement!", err } + defer stmt.Close() stmt2, err := db.Prepare(sql2) if err != nil { return "[ERROR]Illegal SQL statement!", err } + defer stmt2.Close() for _, balanceName := range balanceNames { stmt.Exec(balanceName) stmt2.Exec(balanceName) diff --git a/server/dao/console-sqlite3/dao-service/add.go b/server/dao/console-sqlite3/dao-service/add.go index bfc59b45e2dacdfefc9a981285dda72a72efe2af..c5d117106759f78aad8739c3dcf70041f763eb4c 100644 --- a/server/dao/console-sqlite3/dao-service/add.go +++ b/server/dao/console-sqlite3/dao-service/add.go @@ -17,7 +17,7 @@ func Add(name, driver, desc, config, clusterConfig string, isDefault, healthChec if e != nil { return e } - + defer stmt.Close() _, err := stmt.Exec(name, driver, isDefault, desc, config, clusterConfig, healthCheck, healthCheckPath, healthCheckPeriod, healthCheckCode, healthCheckTimeOut, now, now) return err } diff --git a/server/dao/console-sqlite3/gateway.go b/server/dao/console-sqlite3/gateway.go index e77ec6627734456d5ff591ce42dd18f0c71b5535..8c87ac9664d2f75d3782a54c214a38159d074c69 100644 --- a/server/dao/console-sqlite3/gateway.go +++ b/server/dao/console-sqlite3/gateway.go @@ -38,6 +38,7 @@ func EditGatewayBaseConfig(successCode string, nodeUpdatePeriod, monitorUpdatePe if err != nil { return false, "[ERROR]Illegal SQL Statement!", err } + defer stmt.Close() _, err = stmt.Exec(successCode, nodeUpdatePeriod, monitorUpdatePeriod, monitorTimeout) if err != nil { return false, "[ERROR]Fail to excute SQL Statement!", err @@ -60,6 +61,7 @@ func EditGatewayAlarmConfig(apiAlertInfo, sender, senderPassword, smtpAddress st if err != nil { return false, "[ERROR]Illegal SQL Statement!", err } + defer stmt.Close() _, err = stmt.Exec(apiAlertInfo, alertStatus, sender, senderPassword, smtpAddress, smtpPort, smtpProtocol) if err != nil { return false, "[ERROR]Fail to excute SQL Statement!", err diff --git a/server/dao/console-sqlite3/node.go b/server/dao/console-sqlite3/node.go index 397492dfe3f0ffa0d8e2fadd684229cc21cf5637..11ebf8e69d217e6fb253c3f9fc3ad72542c1507e 100644 --- a/server/dao/console-sqlite3/node.go +++ b/server/dao/console-sqlite3/node.go @@ -203,11 +203,13 @@ func UpdateAllNodeClusterID(clusterID int) { _, err := Tx.Exec(sql, clusterID) if err != nil { Tx.Rollback() + return } sql = "UPDATE goku_node_group SET clusterID = ?;" _, err = Tx.Exec(sql, clusterID) if err != nil { Tx.Rollback() + return } Tx.Commit() } diff --git a/server/dao/console-sqlite3/project.go b/server/dao/console-sqlite3/project.go index 2287263d6c7db352b2c8d893c398e4f0389b06a4..622e382204959ba98035fc5091a0499dfc585170 100644 --- a/server/dao/console-sqlite3/project.go +++ b/server/dao/console-sqlite3/project.go @@ -54,6 +54,7 @@ func DeleteProject(projectID int) (bool, string, error) { sql := "SELECT groupID FROM goku_gateway_api_group WHERE projectID = ?;" rows, err := Tx.Query(sql, projectID) if err != nil { + Tx.Rollback() return false, "", err } //延时关闭Rows diff --git a/server/dao/console-sqlite3/strategy.go b/server/dao/console-sqlite3/strategy.go index 485f0600c6b34b84451b09dd6645449ffad73d9d..e16b0fff2263d07306a22cfa57f8e6095b573dca 100644 --- a/server/dao/console-sqlite3/strategy.go +++ b/server/dao/console-sqlite3/strategy.go @@ -30,7 +30,7 @@ func AddStrategy(strategyName string, groupID int) (bool, string, error) { return false, "[ERROR]Empty strategy id !", nil } stmt, err := db.Prepare(`INSERT INTO goku_gateway_strategy (strategyID,strategyName,updateTime,createTime,groupID) VALUES (?,?,?,?,?);`) - + defer stmt.Close() if err != nil { return false, "[ERROR]Illegal SQL statement!", err } diff --git a/server/dao/console-sqlite3/strategyPlugin.go b/server/dao/console-sqlite3/strategyPlugin.go index f375b012d3995f9b947724512baca0c48eef78f3..1cae721a6258f9c25e70f2c882bed5232bba840a 100644 --- a/server/dao/console-sqlite3/strategyPlugin.go +++ b/server/dao/console-sqlite3/strategyPlugin.go @@ -27,7 +27,6 @@ func AddPluginToStrategy(pluginName, config, strategyID string) (bool, interface result, err := Tx.Exec("INSERT INTO goku_conn_plugin_strategy (pluginName,pluginConfig,strategyID,createTime,updateTime,pluginStatus) VALUES (?,?,?,?,?,?);", pluginName, config, strategyID, now, now, 1) if err != nil { Tx.Rollback() - panic(err) return false, "[ERROR]Fail to insert data", errors.New("[ERROR]Fail to insert data") } connID, err := result.LastInsertId()