update.go 1.4 KB
Newer Older
E
eoLinker API Management 已提交
1 2 3
package dao_balance_update

import (
黄孟柱 已提交
4
	"github.com/eolinker/goku-api-gateway/common/database"
Y
Your Name 已提交
5
	dao_service2 "github.com/eolinker/goku-api-gateway/server/dao/console-sqlite3/dao-service"
黄孟柱 已提交
6
	entity "github.com/eolinker/goku-api-gateway/server/entity/balance-entity"
E
eoLinker API Management 已提交
7 8
)

Y
Your Name 已提交
9
//GetAllOldVerSion 获取所有旧负载配置
Y
Your Name 已提交
10
func GetAllOldVerSion() ([]*entity.BalanceInfoEntity, error) {
E
eoLinker API Management 已提交
11
	const sql = "SELECT `balanceName`,IFNULL(`balanceDesc`, ''),IFNULL(`balanceConfig`, ''),IFNULL(`defaultConfig`, ''),IFNULL(`clusterConfig`, ''),`updateTime`,`createTime` FROM `goku_balance` WHERE `serviceName` = '';"
Y
Your Name 已提交
12 13 14 15
	db := database.GetConnection()
	rows, err := db.Query(sql)
	if err != nil {
		return nil, err
E
eoLinker API Management 已提交
16 17 18
	}
	defer rows.Close()

Y
Your Name 已提交
19 20 21 22 23 24
	r := make([]*entity.BalanceInfoEntity, 0, 20)
	for rows.Next() {
		v := new(entity.BalanceInfoEntity)
		err := rows.Scan(&v.Name, &v.Desc, &v.OldVersionConfig, &v.DefaultConfig, &v.ClusterConfig, &v.UpdateTime, &v.CreateTime)
		if err != nil {
			return nil, err
E
eoLinker API Management 已提交
25
		}
Y
Your Name 已提交
26
		r = append(r, v)
E
eoLinker API Management 已提交
27 28
	}

Y
Your Name 已提交
29
	return r, nil
E
eoLinker API Management 已提交
30 31
}

Y
Your Name 已提交
32
//GetDefaultServiceStatic 获取默认静态负载
Y
Your Name 已提交
33
func GetDefaultServiceStatic() string {
E
eoLinker API Management 已提交
34 35

	tx := database.GetConnection()
Y
Your Name 已提交
36 37 38 39
	name := ""
	err := tx.QueryRow("SELECT `name` FROM `goku_service_config` WHERE `driver`='static' ORDER BY  `default` DESC LIMIT 1; ").Scan(&name)
	if err != nil {
		name = "static"
Y
Your Name 已提交
40
		dao_service2.Add(name, "static", "默认静态服务", "", "", false, false, "", "", 5, 300)
E
eoLinker API Management 已提交
41 42 43
	}

	return name
Y
Your Name 已提交
44
}