add.go 4.5 KB
Newer Older
Y
Your Name 已提交
1
package daobalance
E
eoLinker API Management 已提交
2 3

import (
黄孟柱 已提交
4
	"github.com/eolinker/goku-api-gateway/common/database"
E
eoLinker API Management 已提交
5 6
)

Y
Your Name 已提交
7
//Add 新增负载
E
eoLinker API Management 已提交
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
func Add(name, serviceName, desc, appName, static, staticCluster, now string) (string, error) {

	//const sql = "INSERT INTO goku_balance (`balanceName`,`serviceName`,`appName`,`balanceDesc`,`static`,`staticCluster`,`createTime`,`updateTime`) VALUES (?,?,?,?,?,?,?,?,);"
	//
	//db := database.GetConnection()
	//stmt, err := db.Prepare(sql)
	//if err != nil {
	//	return "[ERROR]Illegal SQL statement!", err
	//}
	//defer stmt.Close()
	//_, err = stmt.Exec(name,serviceName,appName, desc, static, staticCluster, now, now)
	//if err != nil {
	//	return "[ERROR]Failed to add data!", err
	//}
	return "", nil
}
Y
Your Name 已提交
24 25

//AddStatic 新增静态
E
eoLinker API Management 已提交
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
func AddStatic(name, serviceName, static, staticCluster, desc, now string) (string, error) {

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

	db := database.GetConnection()
	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 已提交
42 43

//AddDiscovery 新增服务发现
E
eoLinker API Management 已提交
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
func AddDiscovery(name, serviceName, appName, desc, now string) (string, error) {

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

	db := database.GetConnection()
	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 已提交
60 61

//SaveStatic 保存静态
E
eoLinker API Management 已提交
62 63 64 65 66 67 68 69 70 71 72 73 74 75
func SaveStatic(name, serviceName, static, staticCluster, desc string, now string) (string, error) {
	const sql = "UPDATE `goku_balance` SET `serviceName`=? ,`static` = ?,`staticCluster`=?,`balanceDesc` =?,`updateTime`=? WHERE `balanceName`=?;"
	db := database.GetConnection()
	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 已提交
76 77

//SaveDiscover 保存服务发现
E
eoLinker API Management 已提交
78 79 80 81 82 83 84 85 86 87 88 89 90 91
func SaveDiscover(name, serviceName, appName, desc string, now string) (string, error) {
	const sql = "UPDATE `goku_balance` SET `serviceName`=? ,`appName` = ?,`balanceDesc` =?,`updateTime`=? WHERE `balanceName`=?;"
	db := database.GetConnection()
	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 已提交
92 93

//Save 保存
E
eoLinker API Management 已提交
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
func Save(name, desc, static, staticCluster, now string) (string, error) {
	//const sql = "UPDATE `goku_balance` SET `balanceDesc` = ?,`static` =?,`staticCluster`=?,`updateTime`=? WHERE `balanceName` = ?;"
	//
	//db := database.GetConnection()
	//stmt, err := db.Prepare(sql)
	//if err != nil {
	//	return "[ERROR]Illegal SQL statement!", err
	//}
	//defer stmt.Close()
	//_, err = stmt.Exec(desc, defaultConfig, clusterConfig, now, name)
	//if err != nil {
	//	return "[ERROR]Failed to add data!", err
	//}
	return "", nil
}

Y
Your Name 已提交
110
//Delete 删除
E
eoLinker API Management 已提交
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
func Delete(name string) (string, error) {
	const sql = "DELETE FROM `goku_balance` WHERE  `balanceName`= ?;"
	db := database.GetConnection()
	stmt, err := db.Prepare(sql)
	if err != nil {
		return "[ERROR]Illegal SQL statement!", err
	}
	_, err = stmt.Exec(name)
	if err != nil {
		return "[ERROR]DELETE fail", err
	}
	return "", nil

}

Y
Your Name 已提交
126
//BatchDelete 批量删除负载
E
eoLinker API Management 已提交
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
func BatchDelete(balanceNames []string) (string, error) {
	db := database.GetConnection()
	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
	}
	stmt2, err := db.Prepare(sql2)
	if err != nil {
		return "[ERROR]Illegal SQL statement!", err
	}
	for _, balanceName := range balanceNames {
		stmt.Exec(balanceName)
		stmt2.Exec(balanceName)
	}
	return "", nil
}