balance.go 864 字节
Newer Older
Y
Your Name 已提交
1
package daobalance
E
eoLinker API Management 已提交
2 3

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

Y
Your Name 已提交
8
//GetAllBalance 获取负载列表
Y
Your Name 已提交
9
func GetAllBalance() ([]*entity.Balance, error) {
E
eoLinker API Management 已提交
10
	const sql = "SELECT A.`balanceName`,A.`serviceName`,IFNULL(B.`driver`,''),A.`appName`,IFNULL(A.`static`,''),IFNULL(A.`staticCluster`,'') FROM `goku_balance` A LEFT JOIN `goku_service_config` B ON A.`serviceName` = B.`name`;"
Y
Your Name 已提交
11 12 13 14
	db := database.GetConnection()
	rows, err := db.Query(sql)
	if err != nil {
		return nil, err
E
eoLinker API Management 已提交
15 16 17
	}
	defer rows.Close()

Y
Your Name 已提交
18 19 20 21 22 23
	r := make([]*entity.Balance, 0, 20)
	for rows.Next() {
		v := new(entity.Balance)
		err := rows.Scan(&v.Name, &v.ServiceName, &v.ServiceDriver, &v.AppName, &v.Static, &v.StaticCluster)
		if err != nil {
			return nil, err
E
eoLinker API Management 已提交
24
		}
Y
Your Name 已提交
25
		r = append(r, v.Type())
E
eoLinker API Management 已提交
26
	}
Y
Your Name 已提交
27 28
	return r, nil
}