balance.go 830 字节
Newer Older
E
eoLinker API Management 已提交
1 2 3
package dao_balance

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
func GetAllBalance() ([]*entity.Balance, error) {
E
eoLinker API Management 已提交
9
	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 已提交
10 11 12 13
	db := database.GetConnection()
	rows, err := db.Query(sql)
	if err != nil {
		return nil, err
E
eoLinker API Management 已提交
14 15 16
	}
	defer rows.Close()

Y
Your Name 已提交
17 18 19 20 21 22
	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 已提交
23
		}
Y
Your Name 已提交
24
		r = append(r, v.Type())
E
eoLinker API Management 已提交
25
	}
Y
Your Name 已提交
26 27
	return r, nil
}