add.go 3.3 KB
Newer Older
Y
Your Name 已提交
1
package dao_balance
E
eoLinker API Management 已提交
2

Y
Your Name 已提交
3
//AddStatic 新增静态负载
Y
Your Name 已提交
4
func (b *BalanceDao) AddStatic(name, serviceName, static, staticCluster, desc, now string) (string, error) {
E
eoLinker API Management 已提交
5 6 7

	const sql = "INSERT INTO goku_balance (`balanceName`,`serviceName`,`static`,`staticCluster`,`balanceDesc`,`createTime`,`updateTime`,`appName`,`defaultConfig`,`clusterConfig`,`balanceConfig`) VALUES (?,?,?,?,?,?,?,'','','','');"

Y
Your Name 已提交
8
	db := b.db
E
eoLinker API Management 已提交
9 10 11 12 13 14 15 16 17 18 19
	stmt, err := db.Prepare(sql)
	if err != nil {
		return "[ERROR]Illegal SQL statement!", err
	}
	defer stmt.Close()
	_, err = stmt.Exec(name, serviceName, static, staticCluster, desc, now, now)
	if err != nil {
		return "[ERROR]Failed to add data!", err
	}
	return "", nil
}
Y
Your Name 已提交
20 21

//AddDiscovery 新增服务发现
Y
Your Name 已提交
22
func (b *BalanceDao) AddDiscovery(name, serviceName, appName, desc, now string) (string, error) {
E
eoLinker API Management 已提交
23 24 25

	const sql = "INSERT INTO goku_balance (`balanceName`,`serviceName`,`appName`,`balanceDesc`,`createTime`,`updateTime`,`static`,`staticCluster`,`defaultConfig`,`clusterConfig`,`balanceConfig`) VALUES (?,?,?,?,?,?,'','','','','');"

Y
Your Name 已提交
26
	db := b.db
E
eoLinker API Management 已提交
27 28 29 30 31 32 33 34 35 36 37
	stmt, err := db.Prepare(sql)
	if err != nil {
		return "[ERROR]Illegal SQL statement!", err
	}
	defer stmt.Close()
	_, err = stmt.Exec(name, serviceName, appName, desc, now, now)
	if err != nil {
		return "[ERROR]Failed to add data!", err
	}
	return "", nil
}
Y
Your Name 已提交
38

Y
Your Name 已提交
39
//SaveStatic 保存静态负载信息
Y
Your Name 已提交
40
func (b *BalanceDao) SaveStatic(name, serviceName, static, staticCluster, desc string, now string) (string, error) {
E
eoLinker API Management 已提交
41
	const sql = "UPDATE `goku_balance` SET `serviceName`=? ,`static` = ?,`staticCluster`=?,`balanceDesc` =?,`updateTime`=? WHERE `balanceName`=?;"
Y
Your Name 已提交
42
	db := b.db
E
eoLinker API Management 已提交
43 44 45 46 47 48 49 50 51 52 53
	stmt, err := db.Prepare(sql)
	if err != nil {
		return "[ERROR]Illegal SQL statement!", err
	}
	defer stmt.Close()
	_, err = stmt.Exec(serviceName, static, staticCluster, desc, now, name)
	if err != nil {
		return "[ERROR]Failed to add data!", err
	}
	return "", nil
}
Y
Your Name 已提交
54

Y
Your Name 已提交
55
//SaveDiscover 保存服务发现信息
Y
Your Name 已提交
56
func (b *BalanceDao) SaveDiscover(name, serviceName, appName, desc string, now string) (string, error) {
E
eoLinker API Management 已提交
57
	const sql = "UPDATE `goku_balance` SET `serviceName`=? ,`appName` = ?,`balanceDesc` =?,`updateTime`=? WHERE `balanceName`=?;"
Y
Your Name 已提交
58
	db := b.db
E
eoLinker API Management 已提交
59 60 61 62 63 64 65 66 67 68 69
	stmt, err := db.Prepare(sql)
	if err != nil {
		return "[ERROR]Illegal SQL statement!", err
	}
	defer stmt.Close()
	_, err = stmt.Exec(serviceName, appName, desc, now, name)
	if err != nil {
		return "[ERROR]Failed to add data!", err
	}
	return "", nil
}
Y
Your Name 已提交
70

Y
Your Name 已提交
71
//Delete 删除负载
Y
Your Name 已提交
72
func (b *BalanceDao) Delete(name string) (string, error) {
E
eoLinker API Management 已提交
73
	const sql = "DELETE FROM `goku_balance` WHERE  `balanceName`= ?;"
Y
Your Name 已提交
74
	db := b.db
E
eoLinker API Management 已提交
75 76 77 78
	stmt, err := db.Prepare(sql)
	if err != nil {
		return "[ERROR]Illegal SQL statement!", err
	}
79
	defer stmt.Close()
E
eoLinker API Management 已提交
80 81 82 83 84 85 86
	_, err = stmt.Exec(name)
	if err != nil {
		return "[ERROR]DELETE fail", err
	}
	return "", nil
}

Y
Your Name 已提交
87
//BatchDelete 批量删除负载
Y
Your Name 已提交
88 89
func (b *BalanceDao) BatchDelete(balanceNames []string) (string, error) {
	db := b.db
E
eoLinker API Management 已提交
90 91 92 93 94 95
	sql := "DELETE FROM `goku_balance` WHERE  `balanceName` = ?;"
	sql2 := "UPDATE goku_conn_strategy_api SET target = '' WHERE target = ?"
	stmt, err := db.Prepare(sql)
	if err != nil {
		return "[ERROR]Illegal SQL statement!", err
	}
96
	defer stmt.Close()
E
eoLinker API Management 已提交
97 98 99 100
	stmt2, err := db.Prepare(sql2)
	if err != nil {
		return "[ERROR]Illegal SQL statement!", err
	}
101
	defer stmt2.Close()
E
eoLinker API Management 已提交
102 103 104 105 106 107
	for _, balanceName := range balanceNames {
		stmt.Exec(balanceName)
		stmt2.Exec(balanceName)
	}
	return "", nil
}