strategy.go 1.1 KB
Newer Older
Y
Your Name 已提交
1
package daostrategy
E
eoLinker API Management 已提交
2 3

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

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

Y
Your Name 已提交
10
//GetAllStrategy 获取所有策略列表
E
eoLinker API Management 已提交
11 12 13 14 15 16 17 18 19 20 21 22 23 24
func GetAllStrategy() (map[string]*entity.Strategy, *entity.Strategy, error) {
	//const sql = "SELECT `strategyID`,`strategyName`,`auth` ,`strategyType` FROM `goku_gateway_strategy` WHERE `enableStatus` = 1;"
	const sql = "SELECT `strategyID`,`strategyName`,`auth`,`enableStatus` ,`strategyType` FROM `goku_gateway_strategy`;"

	stmt, e := database.GetConnection().Prepare(sql)
	if e != nil {
		return nil, nil, e
	}
	defer stmt.Close()
	rows, e := stmt.Query()
	if e != nil {
		return nil, nil, e
	}
	defer rows.Close()
Y
Your Name 已提交
25
	var def *entity.Strategy
E
eoLinker API Management 已提交
26 27 28 29 30
	strategys := make(map[string]*entity.Strategy)
	for rows.Next() {
		s := new(entity.Strategy)
		err := rows.Scan(&s.StrategyID, &s.StrategyName, &s.Auth, &s.EnableStatus, &s.StrategyType)
		if err != nil {
Y
Your Name 已提交
31
			log.Warn("GetAllStrategy ", err)
E
eoLinker API Management 已提交
32 33 34 35 36 37 38 39 40 41 42
			continue
		}

		strategys[s.StrategyID] = s
		if s.StrategyType == 1 {
			def = s
		}
	}

	return strategys, def, nil
}