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) {
|
||||
m, err := LoadAdminModuleMapping()
|
||||
m, err := loadAdminModuleMapping()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
func TestLoadUIConfig(t *testing.T) {
|
||||
for i := 0; i < 10; i++ {
|
||||
before := time.Now()
|
||||
config, err := LoadUIConfig()
|
||||
config, err := LoadAdminUIConfig()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -20,7 +20,7 @@ func TestLoadUIConfig(t *testing.T) {
|
||||
|
||||
func TestLoadUIConfig2(t *testing.T) {
|
||||
for i := 0; i < 10; i++ {
|
||||
config, err := LoadUIConfig()
|
||||
config, err := LoadAdminUIConfig()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -14,13 +14,7 @@ func TestLoadAPIConfig(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestAPIConfig_WriteFile(t *testing.T) {
|
||||
config := &APIConfig{
|
||||
RPC: struct {
|
||||
Endpoints []string `yaml:"endpoints"`
|
||||
}{},
|
||||
NodeId: "1",
|
||||
Secret: "2",
|
||||
}
|
||||
config := &APIConfig{}
|
||||
err := config.WriteFile("/tmp/api_config.yaml")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
@@ -25,6 +25,7 @@ func (this *DeleteAction) RunPost(params struct {
|
||||
var apiNode = nodeResp.ApiNode
|
||||
if apiNode == nil {
|
||||
this.Success()
|
||||
return
|
||||
}
|
||||
if apiNode.IsOn {
|
||||
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()
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ func (this *UpdatePopupAction) RunPost(params struct {
|
||||
Must *actions.Must
|
||||
CSRF *actionutils.CSRF
|
||||
}) {
|
||||
defer this.CreateLogInfo("修改流量价格项目", params.ItemId)
|
||||
defer this.CreateLogInfo("修改流量价格项目 %d", params.ItemId)
|
||||
|
||||
params.Must.
|
||||
Field("name", params.Name).
|
||||
|
||||
@@ -80,9 +80,9 @@ func (this *UpdateIPPopupAction) RunPost(params struct {
|
||||
|
||||
var ipToLong uint64
|
||||
if len(params.IpTo) > 0 && !utils.IsIPv4(params.IpTo) {
|
||||
ipToLong = utils.IP2Long(params.IpTo)
|
||||
this.Fail("请输入正确的结束IP")
|
||||
}
|
||||
ipToLong = utils.IP2Long(params.IpTo)
|
||||
|
||||
if ipFromLong > 0 && ipToLong > 0 && ipFromLong > ipToLong {
|
||||
params.IpTo, params.IpFrom = params.IpFrom, params.IpTo
|
||||
|
||||
@@ -109,6 +109,10 @@ func (this *SettingAction) RunPost(params struct {
|
||||
FollowRedirects: reverseProxyConfig.FollowRedirects,
|
||||
ProxyProtocolJSON: proxyProtocolJSON,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
|
||||
@@ -24,5 +24,4 @@ func (this *IndexAction) RunGet(params struct {
|
||||
} else {
|
||||
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,
|
||||
ProxyProtocolJSON: proxyProtocolJSON,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
|
||||
@@ -98,6 +98,10 @@ func (this *SettingAction) RunPost(params struct {
|
||||
AddHeaders: reverseProxyConfig.AddHeaders,
|
||||
FollowRedirects: reverseProxyConfig.FollowRedirects,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
|
||||
@@ -79,9 +79,9 @@ func (this *UpdateIPPopupAction) RunPost(params struct {
|
||||
|
||||
var ipToLong uint64
|
||||
if len(params.IpTo) > 0 && !utils.IsIPv4(params.IpTo) {
|
||||
ipToLong = utils.IP2Long(params.IpTo)
|
||||
this.Fail("请输入正确的结束IP")
|
||||
}
|
||||
ipToLong = utils.IP2Long(params.IpTo)
|
||||
|
||||
if ipFromLong > 0 && ipToLong > 0 && ipFromLong > ipToLong {
|
||||
params.IpTo, params.IpFrom = params.IpFrom, params.IpTo
|
||||
|
||||
@@ -97,9 +97,9 @@ func (this *CreateIPPopupAction) RunPost(params struct {
|
||||
|
||||
var ipToLong uint64
|
||||
if len(params.IpTo) > 0 && !utils.IsIPv4(params.IpTo) {
|
||||
ipToLong = utils.IP2Long(params.IpTo)
|
||||
this.Fail("请输入正确的结束IP")
|
||||
}
|
||||
ipToLong = utils.IP2Long(params.IpTo)
|
||||
|
||||
if ipFromLong > 0 && ipToLong > 0 && ipFromLong > ipToLong {
|
||||
params.IpTo, params.IpFrom = params.IpFrom, params.IpTo
|
||||
|
||||
@@ -79,9 +79,9 @@ func (this *UpdateIPPopupAction) RunPost(params struct {
|
||||
|
||||
var ipToLong uint64
|
||||
if len(params.IpTo) > 0 && !utils.IsIPv4(params.IpTo) {
|
||||
ipToLong = utils.IP2Long(params.IpTo)
|
||||
this.Fail("请输入正确的结束IP")
|
||||
}
|
||||
ipToLong = utils.IP2Long(params.IpTo)
|
||||
|
||||
if ipFromLong > 0 && ipToLong > 0 && ipFromLong > ipToLong {
|
||||
params.IpTo, params.IpFrom = params.IpFrom, params.IpTo
|
||||
|
||||
@@ -41,9 +41,6 @@ func (this *UpdateRefsAction) RunPost(params struct {
|
||||
|
||||
// 校验配置
|
||||
var cacheConfig = webConfig.Cache
|
||||
if webConfig == nil {
|
||||
this.Success()
|
||||
}
|
||||
|
||||
var refs = []*serverconfigs.HTTPCacheRef{}
|
||||
err = json.Unmarshal(params.RefsJSON, &refs)
|
||||
|
||||
@@ -100,6 +100,10 @@ func (this *SettingAction) RunPost(params struct {
|
||||
FollowRedirects: reverseProxyConfig.FollowRedirects,
|
||||
ProxyProtocolJSON: proxyProtocolJSON,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
|
||||
@@ -79,9 +79,9 @@ func (this *UpdateIPPopupAction) RunPost(params struct {
|
||||
|
||||
var ipToLong uint64
|
||||
if len(params.IpTo) > 0 && !utils.IsIPv4(params.IpTo) {
|
||||
ipToLong = utils.IP2Long(params.IpTo)
|
||||
this.Fail("请输入正确的结束IP")
|
||||
}
|
||||
ipToLong = utils.IP2Long(params.IpTo)
|
||||
|
||||
if ipFromLong > 0 && ipToLong > 0 && ipFromLong > ipToLong {
|
||||
params.IpTo, params.IpFrom = params.IpFrom, params.IpTo
|
||||
|
||||
@@ -26,7 +26,7 @@ func (this *CountryOptionsAction) RunPost(params struct{}) {
|
||||
}
|
||||
|
||||
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])
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user