1 Star 0 Fork 2

thubier/GateKeeper

forked from DiDi-opensource/GateKeeper 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
main.go 2.55 KB
一键复制 编辑 原始数据 按行查看 历史
baoqi 提交于 2021-11-09 19:04 . network test
package main
import (
"github.com/didi/gatekeeper/dashboard_router"
"github.com/didi/gatekeeper/golang_common/lib"
"github.com/didi/gatekeeper/golang_common/zerolog/log"
"github.com/didi/gatekeeper/grpc_proxy_router"
"github.com/didi/gatekeeper/handler"
"github.com/didi/gatekeeper/http_proxy_router"
"github.com/didi/gatekeeper/tcp_proxy_router"
_ "net/http/pprof"
"os"
"os/signal"
"syscall"
)
func main() {
if err := lib.CmdExecute(); err != nil || lib.GetCmdPanelType() == "" {
os.Exit(1)
}
if lib.GetCmdPanelType() == "proxy" {
startProxy()
}
if lib.GetCmdPanelType() == "control" {
startControl()
}
if lib.GetCmdPanelType() == "both" {
startBoth()
}
}
func startControl() {
log.Info().Msg(lib.Purple("start controller application"))
lib.InitConf(lib.GetCmdConfPath())
defer lib.DestroyConf()
handler.ServiceManagerHandler.LoadAndWatch()
dashboard_router.HttpServerRun()
quit := make(chan os.Signal)
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
<-quit
dashboard_router.HttpServerStop()
}
func startProxy() {
log.Info().Msg(lib.Purple("start proxy application"))
lib.InitConf(lib.GetCmdConfPath())
defer lib.DestroyConf()
handler.ServiceManagerHandler.LoadAndWatch()
handler.AppManagerHandler.LoadAndWatch()
go func() {
http_proxy_router.HttpServerRun()
}()
go func() {
http_proxy_router.HttpsServerRun()
}()
go func() {
tcp_proxy_router.TcpManagerHandler.TcpServerRun()
}()
go func() {
grpc_proxy_router.GrpcManagerHandler.GrpcServerRun()
}()
quit := make(chan os.Signal)
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
<-quit
tcp_proxy_router.TcpManagerHandler.TcpServerStop()
grpc_proxy_router.GrpcManagerHandler.GrpcServerStop()
http_proxy_router.HttpServerStop()
http_proxy_router.HttpsServerStop()
}
func startBoth() {
log.Info().Msg(lib.Purple("start proxy application"))
lib.InitConf(lib.GetCmdConfPath())
defer lib.DestroyConf()
handler.ServiceManagerHandler.LoadAndWatch()
handler.AppManagerHandler.LoadAndWatch()
dashboard_router.HttpServerRun()
go func() {
http_proxy_router.HttpServerRun()
}()
go func() {
http_proxy_router.HttpsServerRun()
}()
go func() {
tcp_proxy_router.TcpManagerHandler.TcpServerRun()
}()
go func() {
grpc_proxy_router.GrpcManagerHandler.GrpcServerRun()
}()
quit := make(chan os.Signal)
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
<-quit
dashboard_router.HttpServerStop()
tcp_proxy_router.TcpManagerHandler.TcpServerStop()
grpc_proxy_router.GrpcManagerHandler.GrpcServerStop()
http_proxy_router.HttpServerStop()
http_proxy_router.HttpsServerStop()
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/thubier/GateKeeper.git
git@gitee.com:thubier/GateKeeper.git
thubier
GateKeeper
GateKeeper
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385