get.go 1.0 KB
Newer Older
E
eoLinker API Management 已提交
1 2 3 4
package dao_service

import (
	"fmt"
Y
Your Name 已提交
5

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

Y
Your Name 已提交
9 10
const sqlGet = "SELECT `name`,`driver`,`default`,`desc`,`config`,`clusterConfig`,`healthCheck`,`healthCheckPath`,`healthCheckPeriod`,`healthCheckCode`,`healthCheckTimeOut`,`createTime`,`updateTime` FROM `goku_service_config` WHERE `name`=?; "

Y
Your Name 已提交
11
//Get 获取服务发现信息
Y
Your Name 已提交
12
func (d *ServiceDao) Get(name string) (*entity.Service, error) {
E
eoLinker API Management 已提交
13

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

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

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

Y
Your Name 已提交
46
		return v, nil
E
eoLinker API Management 已提交
47 48
	}

Y
Your Name 已提交
49
	return nil, fmt.Errorf("no that service:%s", name)
E
eoLinker API Management 已提交
50

Y
Your Name 已提交
51
}