gateway.go 2.2 KB
Newer Older
E
eoLinker API Management 已提交
1 2 3
package gateway

import (
Y
Your Name 已提交
4
	"github.com/eolinker/goku-api-gateway/common/pdao"
Y
Your Name 已提交
5
	v "github.com/eolinker/goku-api-gateway/common/version"
Y
Your Name 已提交
6 7
	"github.com/eolinker/goku-api-gateway/server/dao"
	entity "github.com/eolinker/goku-api-gateway/server/entity/console-entity"
E
eoLinker API Management 已提交
8 9
)

Y
Your Name 已提交
10 11 12 13 14 15 16 17 18 19
var (
	gatewayDao dao.GatewayDao
	pluginDao  dao.PluginDao
	clusterDao dao.ClusterDao
)

func init() {
	pdao.Need(&gatewayDao, &pluginDao, &clusterDao)
}

Y
Your Name 已提交
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
//BaseGatewayInfo 网关基本配置
type BaseGatewayInfo struct {
	NodeCount      int    `json:"nodeCount"`
	NodeStartCount int    `json:"nodeStartCount"`
	NodeStopCount  int    `json:"nodeStopCount"`
	ProjectCount   int    `json:"projectCount"`
	APICount       int    `json:"apiCount"`
	StrategyCount  int    `json:"strategyCount"`
	PluginCount    int    `json:"pluginCount"`
	ClusterCount   int    `json:"clusterCount"`
	Version        string `json:"version"`
}

//SystemInfo 系统配置
type SystemInfo struct {
	BaseInfo BaseGatewayInfo `json:"baseInfo"`
}

Y
Your Name 已提交
38
//GetGatewayConfig 获取网关配置
E
eoLinker API Management 已提交
39
func GetGatewayConfig() (map[string]interface{}, error) {
Y
Your Name 已提交
40
	return gatewayDao.GetGatewayConfig()
E
eoLinker API Management 已提交
41 42
}

Y
Your Name 已提交
43
//EditGatewayBaseConfig 编辑网关基本配置
E
eoLinker API Management 已提交
44
func EditGatewayBaseConfig(successCode string, nodeUpdatePeriod, monitorUpdatePeriod, timeout int) (bool, string, error) {
Y
Your Name 已提交
45 46 47 48 49 50 51
	config := entity.GatewayBasicConfig{
		SuccessCode:         successCode,
		NodeUpdatePeriod:    nodeUpdatePeriod,
		MonitorUpdatePeriod: monitorUpdatePeriod,
		MonitorTimeout:      timeout,
	}
	flag, result, err := gatewayDao.EditGatewayBaseConfig(config)
E
eoLinker API Management 已提交
52 53
	return flag, result, err
}
Y
Your Name 已提交
54 55 56 57

//GetGatewayMonitorSummaryByPeriod 获取监控summary
func GetGatewayMonitorSummaryByPeriod() (bool, *SystemInfo, error) {

Y
Your Name 已提交
58
	nodeStartCount, nodeStopCount, projectCount, apiCount, strategyCount, e := gatewayDao.GetGatewayInfo()
Y
Your Name 已提交
59 60 61 62
	if e != nil {
		return false, nil, e
	}
	info := new(SystemInfo)
Y
Your Name 已提交
63
	info.BaseInfo.PluginCount = pluginDao.GetPluginCount()
Y
Your Name 已提交
64 65 66 67 68
	info.BaseInfo.NodeCount = nodeStartCount + nodeStopCount
	info.BaseInfo.ProjectCount = projectCount
	info.BaseInfo.APICount = apiCount
	info.BaseInfo.StrategyCount = strategyCount
	info.BaseInfo.Version = v.Version
Y
Your Name 已提交
69
	info.BaseInfo.ClusterCount = clusterDao.GetClusterCount()
Y
Your Name 已提交
70 71 72 73

	return true, info, nil

}