Rainbond/api/handler/proxy.go

62 lines
2.0 KiB
Go
Raw Normal View History

2018-03-14 14:12:26 +08:00
// Copyright (C) 2014-2018 Goodrain Co., Ltd.
2017-11-22 14:59:20 +08:00
// RAINBOND, Application Management Platform
2018-03-14 14:33:31 +08:00
2017-11-22 14:59:20 +08:00
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version. For any non-GPL usage of Rainbond,
// one or multiple Commercial Licenses authorized by Goodrain Co., Ltd.
// must be obtained first.
2018-03-14 14:33:31 +08:00
2017-11-22 14:59:20 +08:00
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
2018-03-14 14:33:31 +08:00
2017-11-22 14:59:20 +08:00
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package handler
2017-11-22 14:59:20 +08:00
import (
"github.com/goodrain/rainbond/cmd/api/option"
"github.com/goodrain/rainbond/api/discover"
"github.com/goodrain/rainbond/api/proxy"
2017-11-22 14:59:20 +08:00
)
var nodeProxy proxy.Proxy
2017-12-12 10:07:25 +08:00
var builderProxy proxy.Proxy
var prometheusProxy proxy.Proxy
2017-11-22 14:59:20 +08:00
//InitProxy 初始化
func InitProxy(conf option.Config) {
if nodeProxy == nil {
nodeProxy = proxy.CreateProxy("acp_node", "http", conf.NodeAPI)
discover.GetEndpointDiscover(conf.EtcdEndpoint).AddProject("acp_node", nodeProxy)
}
2017-12-12 10:07:25 +08:00
if builderProxy == nil {
2017-12-12 11:21:34 +08:00
builderProxy = proxy.CreateProxy("builder", "http", conf.BuilderAPI)
discover.GetEndpointDiscover(conf.EtcdEndpoint).AddProject("builder", builderProxy)
2017-12-12 10:07:25 +08:00
}
if prometheusProxy == nil {
2018-03-13 18:33:01 +08:00
prometheusProxy = proxy.CreateProxy("prometheus", "http", []string{"127.0.0.1:9999"})
discover.GetEndpointDiscover(conf.EtcdEndpoint).AddProject("prometheus", prometheusProxy)
}
2017-11-22 14:59:20 +08:00
}
//GetNodeProxy GetNodeProxy
func GetNodeProxy() proxy.Proxy {
return nodeProxy
}
2018-01-18 13:45:24 +08:00
//GetBuilderProxy GetNodeProxy
2017-12-12 10:07:25 +08:00
func GetBuilderProxy() proxy.Proxy {
return builderProxy
}
//GetPrometheusProxy GetPrometheusProxy
func GetPrometheusProxy() proxy.Proxy {
return prometheusProxy
}