阶段性提交

This commit is contained in:
GoEdgeLab
2020-09-13 20:37:07 +08:00
parent 124cbd3302
commit e3501a5a68
155 changed files with 1317 additions and 13193 deletions

View File

@@ -1,97 +1,30 @@
package serverutils
import (
"github.com/iwind/TeaGo/lists"
"github.com/iwind/TeaGo/maps"
"errors"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
"strconv"
)
type ServerType = string
const (
ServerTypeHTTPProxy ServerType = "httpProxy"
ServerTypeHTTPWeb ServerType = "httpWeb"
ServerTypeTCPProxy ServerType = "tcpProxy"
ServerTypeUnixProxy ServerType = "unixProxy"
ServerTypeUDPProxy ServerType = "udp"
)
// 获取所有的服务类型
func AllServerTypes() []maps.Map {
return []maps.Map{
{
"name": "HTTP反向代理",
"code": ServerTypeHTTPProxy,
},
{
"name": "HTTP Web服务",
"code": ServerTypeHTTPWeb,
},
{
"name": "TCP反向代理",
"code": ServerTypeTCPProxy,
},
/**{
"name": "UNIX协议反向代理",
"code": ServerTypeUnixProxy,
},
{
"name": "UDP反向代理",
"code": ServerTypeUDPProxy,
},**/
// 查找Server
func FindServer(p *actionutils.ParentAction, serverId int64) (*pb.Server, *serverconfigs.ServerConfig, bool) {
serverResp, err := p.RPC().ServerRPC().FindEnabledServer(p.AdminContext(), &pb.FindEnabledServerRequest{ServerId: serverId})
if err != nil {
p.ErrorPage(err)
return nil, nil, false
}
}
// 查找服务类型
func FindServerType(code string) maps.Map {
for _, m := range AllServerTypes() {
if m.GetString("code") == code {
return m
}
}
return nil
}
// 获取所有协议
func AllServerProtocolsForType(serverType ServerType) []maps.Map {
protocols := []maps.Map{
{
"name": "HTTP",
"code": "http",
"serverTypes": []ServerType{ServerTypeHTTPProxy, ServerTypeHTTPWeb},
},
{
"name": "HTTPS",
"code": "https",
"serverTypes": []ServerType{ServerTypeHTTPProxy, ServerTypeHTTPWeb},
},
{
"name": "TCP",
"code": "tcp",
"serverTypes": []ServerType{ServerTypeTCPProxy},
},
{
"name": "TLS",
"code": "tls",
"serverTypes": []ServerType{ServerTypeTCPProxy},
},
{
"name": "Unix",
"code": "unix",
"serverTypes": []ServerType{ServerTypeUnixProxy},
},
{
"name": "UDP",
"code": "udp",
"serverTypes": []ServerType{ServerTypeUDPProxy},
},
}
result := []maps.Map{}
for _, p := range protocols {
serverTypes := p.GetSlice("serverTypes")
if lists.Contains(serverTypes, serverType) {
result = append(result, p)
}
}
return result
server := serverResp.Server
if server == nil {
p.ErrorPage(errors.New("not found server with id '" + strconv.FormatInt(serverId, 10) + "'"))
return nil, nil, false
}
config, err := serverconfigs.NewServerConfigFromJSON(server.Config)
if err != nil {
p.ErrorPage(err)
return nil, nil, false
}
return server, config, true
}