strategy.go 1.1 KB
Newer Older
E
eoLinker API Management 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
package dao_strategy

import (
	log "github.com/eolinker/goku/goku-log"

	"github.com/eolinker/goku/common/database"
	entity "github.com/eolinker/goku/server/entity/node-entity"
)

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()
	var def *entity.Strategy = nil
	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 已提交
30
			log.Warn("GetAllStrategy ", err)
E
eoLinker API Management 已提交
31 32 33 34 35 36 37 38 39 40 41
			continue
		}

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

	return strategys, def, nil
}