mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-07 23:30:26 +08:00
优化代码
This commit is contained in:
@@ -6,7 +6,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestLoadAdminModuleMapping(t *testing.T) {
|
func TestLoadAdminModuleMapping(t *testing.T) {
|
||||||
m, err := LoadAdminModuleMapping()
|
m, err := loadAdminModuleMapping()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import (
|
|||||||
func TestLoadUIConfig(t *testing.T) {
|
func TestLoadUIConfig(t *testing.T) {
|
||||||
for i := 0; i < 10; i++ {
|
for i := 0; i < 10; i++ {
|
||||||
before := time.Now()
|
before := time.Now()
|
||||||
config, err := LoadUIConfig()
|
config, err := LoadAdminUIConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@@ -20,7 +20,7 @@ func TestLoadUIConfig(t *testing.T) {
|
|||||||
|
|
||||||
func TestLoadUIConfig2(t *testing.T) {
|
func TestLoadUIConfig2(t *testing.T) {
|
||||||
for i := 0; i < 10; i++ {
|
for i := 0; i < 10; i++ {
|
||||||
config, err := LoadUIConfig()
|
config, err := LoadAdminUIConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,13 +14,7 @@ func TestLoadAPIConfig(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestAPIConfig_WriteFile(t *testing.T) {
|
func TestAPIConfig_WriteFile(t *testing.T) {
|
||||||
config := &APIConfig{
|
config := &APIConfig{}
|
||||||
RPC: struct {
|
|
||||||
Endpoints []string `yaml:"endpoints"`
|
|
||||||
}{},
|
|
||||||
NodeId: "1",
|
|
||||||
Secret: "2",
|
|
||||||
}
|
|
||||||
err := config.WriteFile("/tmp/api_config.yaml")
|
err := config.WriteFile("/tmp/api_config.yaml")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ func (this *DeleteAction) RunPost(params struct {
|
|||||||
var apiNode = nodeResp.ApiNode
|
var apiNode = nodeResp.ApiNode
|
||||||
if apiNode == nil {
|
if apiNode == nil {
|
||||||
this.Success()
|
this.Success()
|
||||||
|
return
|
||||||
}
|
}
|
||||||
if apiNode.IsOn {
|
if apiNode.IsOn {
|
||||||
countResp, err := this.RPC().APINodeRPC().CountAllEnabledAndOnAPINodes(this.AdminContext(), &pb.CountAllEnabledAndOnAPINodesRequest{})
|
countResp, err := this.RPC().APINodeRPC().CountAllEnabledAndOnAPINodes(this.AdminContext(), &pb.CountAllEnabledAndOnAPINodesRequest{})
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ func (this *CreatePopupAction) RunPost(params struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 创建日志
|
// 创建日志
|
||||||
defer this.CreateLog(oplogs.LevelInfo, "创建节点分组", createResp.NodeGroupId)
|
defer this.CreateLog(oplogs.LevelInfo, "创建节点分组 %d", createResp.NodeGroupId)
|
||||||
|
|
||||||
this.Success()
|
this.Success()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ func (this *UpdatePopupAction) RunPost(params struct {
|
|||||||
Must *actions.Must
|
Must *actions.Must
|
||||||
CSRF *actionutils.CSRF
|
CSRF *actionutils.CSRF
|
||||||
}) {
|
}) {
|
||||||
defer this.CreateLogInfo("修改流量价格项目", params.ItemId)
|
defer this.CreateLogInfo("修改流量价格项目 %d", params.ItemId)
|
||||||
|
|
||||||
params.Must.
|
params.Must.
|
||||||
Field("name", params.Name).
|
Field("name", params.Name).
|
||||||
|
|||||||
@@ -80,9 +80,9 @@ func (this *UpdateIPPopupAction) RunPost(params struct {
|
|||||||
|
|
||||||
var ipToLong uint64
|
var ipToLong uint64
|
||||||
if len(params.IpTo) > 0 && !utils.IsIPv4(params.IpTo) {
|
if len(params.IpTo) > 0 && !utils.IsIPv4(params.IpTo) {
|
||||||
ipToLong = utils.IP2Long(params.IpTo)
|
|
||||||
this.Fail("请输入正确的结束IP")
|
this.Fail("请输入正确的结束IP")
|
||||||
}
|
}
|
||||||
|
ipToLong = utils.IP2Long(params.IpTo)
|
||||||
|
|
||||||
if ipFromLong > 0 && ipToLong > 0 && ipFromLong > ipToLong {
|
if ipFromLong > 0 && ipToLong > 0 && ipFromLong > ipToLong {
|
||||||
params.IpTo, params.IpFrom = params.IpFrom, params.IpTo
|
params.IpTo, params.IpFrom = params.IpFrom, params.IpTo
|
||||||
|
|||||||
@@ -109,6 +109,10 @@ func (this *SettingAction) RunPost(params struct {
|
|||||||
FollowRedirects: reverseProxyConfig.FollowRedirects,
|
FollowRedirects: reverseProxyConfig.FollowRedirects,
|
||||||
ProxyProtocolJSON: proxyProtocolJSON,
|
ProxyProtocolJSON: proxyProtocolJSON,
|
||||||
})
|
})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
this.Success()
|
this.Success()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,5 +24,4 @@ func (this *IndexAction) RunGet(params struct {
|
|||||||
} else {
|
} else {
|
||||||
this.RedirectURL("/servers/groups/group/settings/httpReverseProxy?groupId=" + types.String(params.GroupId))
|
this.RedirectURL("/servers/groups/group/settings/httpReverseProxy?groupId=" + types.String(params.GroupId))
|
||||||
}
|
}
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -109,6 +109,10 @@ func (this *SettingAction) RunPost(params struct {
|
|||||||
FollowRedirects: reverseProxyConfig.FollowRedirects,
|
FollowRedirects: reverseProxyConfig.FollowRedirects,
|
||||||
ProxyProtocolJSON: proxyProtocolJSON,
|
ProxyProtocolJSON: proxyProtocolJSON,
|
||||||
})
|
})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
this.Success()
|
this.Success()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -96,8 +96,12 @@ func (this *SettingAction) RunPost(params struct {
|
|||||||
StripPrefix: reverseProxyConfig.StripPrefix,
|
StripPrefix: reverseProxyConfig.StripPrefix,
|
||||||
AutoFlush: reverseProxyConfig.AutoFlush,
|
AutoFlush: reverseProxyConfig.AutoFlush,
|
||||||
AddHeaders: reverseProxyConfig.AddHeaders,
|
AddHeaders: reverseProxyConfig.AddHeaders,
|
||||||
FollowRedirects: reverseProxyConfig.FollowRedirects,
|
FollowRedirects: reverseProxyConfig.FollowRedirects,
|
||||||
})
|
})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
this.Success()
|
this.Success()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,9 +79,9 @@ func (this *UpdateIPPopupAction) RunPost(params struct {
|
|||||||
|
|
||||||
var ipToLong uint64
|
var ipToLong uint64
|
||||||
if len(params.IpTo) > 0 && !utils.IsIPv4(params.IpTo) {
|
if len(params.IpTo) > 0 && !utils.IsIPv4(params.IpTo) {
|
||||||
ipToLong = utils.IP2Long(params.IpTo)
|
|
||||||
this.Fail("请输入正确的结束IP")
|
this.Fail("请输入正确的结束IP")
|
||||||
}
|
}
|
||||||
|
ipToLong = utils.IP2Long(params.IpTo)
|
||||||
|
|
||||||
if ipFromLong > 0 && ipToLong > 0 && ipFromLong > ipToLong {
|
if ipFromLong > 0 && ipToLong > 0 && ipFromLong > ipToLong {
|
||||||
params.IpTo, params.IpFrom = params.IpFrom, params.IpTo
|
params.IpTo, params.IpFrom = params.IpFrom, params.IpTo
|
||||||
|
|||||||
@@ -97,9 +97,9 @@ func (this *CreateIPPopupAction) RunPost(params struct {
|
|||||||
|
|
||||||
var ipToLong uint64
|
var ipToLong uint64
|
||||||
if len(params.IpTo) > 0 && !utils.IsIPv4(params.IpTo) {
|
if len(params.IpTo) > 0 && !utils.IsIPv4(params.IpTo) {
|
||||||
ipToLong = utils.IP2Long(params.IpTo)
|
|
||||||
this.Fail("请输入正确的结束IP")
|
this.Fail("请输入正确的结束IP")
|
||||||
}
|
}
|
||||||
|
ipToLong = utils.IP2Long(params.IpTo)
|
||||||
|
|
||||||
if ipFromLong > 0 && ipToLong > 0 && ipFromLong > ipToLong {
|
if ipFromLong > 0 && ipToLong > 0 && ipFromLong > ipToLong {
|
||||||
params.IpTo, params.IpFrom = params.IpFrom, params.IpTo
|
params.IpTo, params.IpFrom = params.IpFrom, params.IpTo
|
||||||
|
|||||||
@@ -79,9 +79,9 @@ func (this *UpdateIPPopupAction) RunPost(params struct {
|
|||||||
|
|
||||||
var ipToLong uint64
|
var ipToLong uint64
|
||||||
if len(params.IpTo) > 0 && !utils.IsIPv4(params.IpTo) {
|
if len(params.IpTo) > 0 && !utils.IsIPv4(params.IpTo) {
|
||||||
ipToLong = utils.IP2Long(params.IpTo)
|
|
||||||
this.Fail("请输入正确的结束IP")
|
this.Fail("请输入正确的结束IP")
|
||||||
}
|
}
|
||||||
|
ipToLong = utils.IP2Long(params.IpTo)
|
||||||
|
|
||||||
if ipFromLong > 0 && ipToLong > 0 && ipFromLong > ipToLong {
|
if ipFromLong > 0 && ipToLong > 0 && ipFromLong > ipToLong {
|
||||||
params.IpTo, params.IpFrom = params.IpFrom, params.IpTo
|
params.IpTo, params.IpFrom = params.IpFrom, params.IpTo
|
||||||
|
|||||||
@@ -41,9 +41,6 @@ func (this *UpdateRefsAction) RunPost(params struct {
|
|||||||
|
|
||||||
// 校验配置
|
// 校验配置
|
||||||
var cacheConfig = webConfig.Cache
|
var cacheConfig = webConfig.Cache
|
||||||
if webConfig == nil {
|
|
||||||
this.Success()
|
|
||||||
}
|
|
||||||
|
|
||||||
var refs = []*serverconfigs.HTTPCacheRef{}
|
var refs = []*serverconfigs.HTTPCacheRef{}
|
||||||
err = json.Unmarshal(params.RefsJSON, &refs)
|
err = json.Unmarshal(params.RefsJSON, &refs)
|
||||||
|
|||||||
@@ -100,6 +100,10 @@ func (this *SettingAction) RunPost(params struct {
|
|||||||
FollowRedirects: reverseProxyConfig.FollowRedirects,
|
FollowRedirects: reverseProxyConfig.FollowRedirects,
|
||||||
ProxyProtocolJSON: proxyProtocolJSON,
|
ProxyProtocolJSON: proxyProtocolJSON,
|
||||||
})
|
})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
this.Success()
|
this.Success()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,9 +79,9 @@ func (this *UpdateIPPopupAction) RunPost(params struct {
|
|||||||
|
|
||||||
var ipToLong uint64
|
var ipToLong uint64
|
||||||
if len(params.IpTo) > 0 && !utils.IsIPv4(params.IpTo) {
|
if len(params.IpTo) > 0 && !utils.IsIPv4(params.IpTo) {
|
||||||
ipToLong = utils.IP2Long(params.IpTo)
|
|
||||||
this.Fail("请输入正确的结束IP")
|
this.Fail("请输入正确的结束IP")
|
||||||
}
|
}
|
||||||
|
ipToLong = utils.IP2Long(params.IpTo)
|
||||||
|
|
||||||
if ipFromLong > 0 && ipToLong > 0 && ipFromLong > ipToLong {
|
if ipFromLong > 0 && ipToLong > 0 && ipFromLong > ipToLong {
|
||||||
params.IpTo, params.IpFrom = params.IpFrom, params.IpTo
|
params.IpTo, params.IpFrom = params.IpFrom, params.IpTo
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ func (this *CountryOptionsAction) RunPost(params struct{}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var letter = ""
|
var letter = ""
|
||||||
if len(country.Pinyin) > 0 && len(country.Pinyin) > 0 && len(country.Pinyin[0]) > 0 {
|
if len(country.Pinyin) > 0 && len(country.Pinyin[0]) > 0 {
|
||||||
letter = strings.ToUpper(country.Pinyin[0][:1])
|
letter = strings.ToUpper(country.Pinyin[0][:1])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user