list.go 1.2 KB
Newer Older
E
eoLinker API Management 已提交
1 2 3 4 5
package dao_service

import (
	"fmt"

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

const sqlList = "SELECT `name`,`driver`,`default`,`desc`,`config`,`clusterConfig`,`healthCheck`,`healthCheckPath`,`healthCheckPeriod`,`healthCheckCode`,`healthCheckTimeOut`,`createTime`,`updateTime` FROM `goku_service_config` %s ORDER BY `updateTime` DESC;"

Y
Your Name 已提交
11
//List 获取服务发现列表
Y
Your Name 已提交
12
func (d *ServiceDao) List(keyword string) ([]*entity.Service, error) {
E
eoLinker API Management 已提交
13 14 15 16 17 18
	where := ""
	if keyword != "" {
		where = fmt.Sprint("where `name` like '%", keyword, "%' OR `driver` like '%", keyword, "%'")
	}

	sql := fmt.Sprintf(sqlList, where)
Y
Your Name 已提交
19
	stmt, e := d.db.Prepare(sql)
E
eoLinker API Management 已提交
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
	if e != nil {
		return nil, e
	}
	defer stmt.Close()
	rows, err := stmt.Query()
	if err != nil {
		return nil, err
	}
	defer rows.Close()

	vs := make([]*entity.Service, 0, 10)

	for rows.Next() {

		v := new(entity.Service)
		er := rows.Scan(&v.Name,
			&v.Driver,
			&v.IsDefault,
			&v.Desc,
			&v.Config,
			&v.ClusterConfig,
			&v.HealthCheck,
			&v.HealthCheckPath,
			&v.HealthCheckPeriod,
			&v.HealthCheckCode,
			&v.HealthCheckTimeOut,
			&v.CreateTime,
			&v.UpdateTime,
		)
		if er != nil {
			return nil, er
		}

		vs = append(vs, v)

	}
	return vs, nil

}