实现节点自动切换到备用IP

This commit is contained in:
GoEdgeLab
2021-09-13 10:51:16 +08:00
parent d4494d0191
commit b53ef45a6a
8 changed files with 115 additions and 7 deletions

View File

@@ -30,6 +30,7 @@ func init() {
Post("/showTip", new(ShowTipAction)).
Post("/hideTip", new(HideTipAction)).
Post("/theme", new(ThemeAction)).
Post("/validateIPs", new(ValidateIPsAction)).
EndAll()
})

View File

@@ -0,0 +1,41 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
package ui
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"net"
"strings"
)
type ValidateIPsAction struct {
actionutils.ParentAction
}
func (this *ValidateIPsAction) RunPost(params struct {
Ips string
}) {
var ips = params.Ips
if len(ips) == 0 {
this.Data["ips"] = []string{}
this.Success()
}
var ipSlice = strings.Split(ips, "\n")
var result = []string{}
for _, ip := range ipSlice {
ip = strings.TrimSpace(ip)
if len(ip) == 0 {
continue
}
data := net.ParseIP(ip)
if len(data) == 0 {
this.Data["failIP"] = ip
this.Fail()
}
result = append(result, ip)
}
this.Data["ips"] = result
this.Success()
}