service.go 1.0 KB
Newer Older
Y
Your Name 已提交
1
package daoservice
E
eoLinker API Management 已提交
2 3

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 9
const sqlList = "SELECT `name`,`driver`,`default`,`desc`,`config`,`clusterConfig`,`healthCheck`,`healthCheckPath`,`healthCheckPeriod`,`healthCheckCode`,`healthCheckTimeOut` FROM `goku_service_config`"

Y
Your Name 已提交
10
//GetAll 获取所有服务发现配置
Y
Your Name 已提交
11
func GetAll() ([]*entity.Service, error) {
E
eoLinker API Management 已提交
12 13

	stmt, e := database.GetConnection().Prepare(sqlList)
Y
Your Name 已提交
14 15
	if e != nil {
		return nil, e
E
eoLinker API Management 已提交
16 17
	}
	defer stmt.Close()
Y
Your Name 已提交
18
	rows, err := stmt.Query()
E
eoLinker API Management 已提交
19

Y
Your Name 已提交
20 21
	if err != nil {
		return nil, err
E
eoLinker API Management 已提交
22 23 24
	}
	defer rows.Close()

Y
Your Name 已提交
25
	vs := make([]*entity.Service, 0, 10)
E
eoLinker API Management 已提交
26

Y
Your Name 已提交
27
	for rows.Next() {
E
eoLinker API Management 已提交
28

Y
Your Name 已提交
29 30
		v := new(entity.Service)
		er := rows.Scan(&v.Name,
E
eoLinker API Management 已提交
31 32 33 34 35 36 37 38 39 40 41
			&v.Driver,
			&v.IsDefault,
			&v.Desc,
			&v.Config,
			&v.ClusterConfig,
			&v.HealthCheck,
			&v.HealthCheckPath,
			&v.HealthCheckPeriod,
			&v.HealthCheckCode,
			&v.HealthCheckTimeOut,
		)
Y
Your Name 已提交
42 43
		if er != nil {
			return nil, er
E
eoLinker API Management 已提交
44 45
		}

Y
Your Name 已提交
46
		vs = append(vs, v)
E
eoLinker API Management 已提交
47
	}
Y
Your Name 已提交
48
	return vs, nil
E
eoLinker API Management 已提交
49

Y
Your Name 已提交
50
}