添加域名时移除多余的端口号

This commit is contained in:
GoEdgeLab
2023-08-20 10:27:55 +08:00
parent d7cedbeda4
commit ffed6bb56f

View File

@@ -4,6 +4,7 @@ import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/maps"
"net"
"net/url"
"regexp"
"strings"
@@ -43,6 +44,14 @@ func (this *AddServerNamePopupAction) RunPost(params struct {
}
}
// 去除端口
if regexp.MustCompile(`:\d+$`).MatchString(serverName) {
host, _, err := net.SplitHostPort(serverName)
if err == nil && len(host) > 0 {
serverName = host
}
}
params.Must.
Field("serverName", serverName).
Require("请输入域名")
@@ -72,6 +81,14 @@ func (this *AddServerNamePopupAction) RunPost(params struct {
}
}
// 去除端口
if regexp.MustCompile(`:\d+$`).MatchString(serverName) {
host, _, err := net.SplitHostPort(serverName)
if err == nil && len(host) > 0 {
serverName = host
}
}
// 转成小写
serverName = strings.ToLower(serverName)