阶段性提交

This commit is contained in:
GoEdgeLab
2020-09-15 14:44:52 +08:00
parent e3501a5a68
commit 4807a6672f
27 changed files with 1354 additions and 115 deletions

View File

@@ -2,12 +2,10 @@ package servers
import (
"encoding/json"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
"github.com/iwind/TeaGo/logs"
"github.com/iwind/TeaGo/maps"
"strings"
)
type IndexAction struct {
@@ -39,70 +37,57 @@ func (this *IndexAction) RunGet(params struct{}) {
}
serverMaps := []maps.Map{}
for _, server := range serversResp.Servers {
// 服务名
serverConfig := &serverconfigs.ServerConfig{}
err = json.Unmarshal(server.Config, &serverConfig)
config := &serverconfigs.ServerConfig{}
err = json.Unmarshal(server.Config, config)
if err != nil {
this.ErrorPage(err)
return
}
err = serverConfig.Init()
if err != nil {
logs.Println("init server '" + serverConfig.Name + "' error: " + err.Error())
}
serverTypeNames := []string{}
// 端口列表
portMaps := []maps.Map{}
if serverConfig.HTTP != nil && serverConfig.HTTP.IsOn {
serverTypeNames = append(serverTypeNames, "HTTP")
for _, listen := range serverConfig.HTTP.Listen {
if len(server.HttpJSON) > 0 && config.HTTP.IsOn {
for _, listen := range config.HTTP.Listen {
portMaps = append(portMaps, maps.Map{
"protocol": listen.Protocol,
"portRange": listen.PortRange,
})
}
}
if serverConfig.HTTPS != nil && serverConfig.HTTPS.IsOn {
serverTypeNames = append(serverTypeNames, "HTTPS")
for _, listen := range serverConfig.HTTPS.Listen {
if config.HTTPS != nil && config.HTTPS.IsOn {
for _, listen := range config.HTTPS.Listen {
portMaps = append(portMaps, maps.Map{
"protocol": listen.Protocol,
"portRange": listen.PortRange,
})
}
}
if serverConfig.TCP != nil && serverConfig.TCP.IsOn {
serverTypeNames = append(serverTypeNames, "TCP")
for _, listen := range serverConfig.TCP.Listen {
if config.TCP != nil && config.TCP.IsOn {
for _, listen := range config.TCP.Listen {
portMaps = append(portMaps, maps.Map{
"protocol": listen.Protocol,
"portRange": listen.PortRange,
})
}
}
if serverConfig.TLS != nil && serverConfig.TLS.IsOn {
serverTypeNames = append(serverTypeNames, "TLS")
for _, listen := range serverConfig.TLS.Listen {
if config.TLS != nil && config.TLS.IsOn {
for _, listen := range config.TLS.Listen {
portMaps = append(portMaps, maps.Map{
"protocol": listen.Protocol,
"portRange": listen.PortRange,
})
}
}
if serverConfig.Unix != nil && serverConfig.Unix.IsOn {
serverTypeNames = append(serverTypeNames, "Unix")
for _, listen := range serverConfig.Unix.Listen {
if config.Unix != nil && config.Unix.IsOn {
for _, listen := range config.Unix.Listen {
portMaps = append(portMaps, maps.Map{
"protocol": listen.Protocol,
"portRange": listen.Host,
})
}
}
if serverConfig.UDP != nil && serverConfig.UDP.IsOn {
serverTypeNames = append(serverTypeNames, "UDP")
for _, listen := range serverConfig.UDP.Listen {
if config.UDP != nil && config.UDP.IsOn {
for _, listen := range config.UDP.Listen {
portMaps = append(portMaps, maps.Map{
"protocol": listen.Protocol,
"portRange": listen.PortRange,
@@ -118,7 +103,7 @@ func (this *IndexAction) RunGet(params struct{}) {
"name": server.Cluster.Name,
},
"ports": portMaps,
"serverTypeName": strings.Join(serverTypeNames, "+"),
"serverTypeName": serverconfigs.FindServerType(server.Type).GetString("name"),
})
}
this.Data["servers"] = serverMaps