优化界面

This commit is contained in:
GoEdgeLab
2022-03-04 17:00:01 +08:00
parent 137de008fc
commit 8a5753326f
6 changed files with 62 additions and 2 deletions

24
internal/utils/json.go Normal file
View File

@@ -0,0 +1,24 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
package utils
import (
"encoding/json"
"reflect"
)
// JSONClone 使用JSON克隆对象
func JSONClone(v interface{}) (interface{}, error) {
data, err := json.Marshal(v)
if err != nil {
return nil, err
}
var nv = reflect.New(reflect.TypeOf(v).Elem()).Interface()
err = json.Unmarshal(data, nv)
if err != nil {
return nil, err
}
return nv, nil
}

View File

@@ -0,0 +1,25 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
package utils_test
import (
"github.com/TeaOSLab/EdgeAdmin/internal/utils"
"testing"
)
func TestJSONClone(t *testing.T) {
type A struct {
B int `json:"b"`
C string `json:"c"`
}
var a = &A{B: 123, C: "456"}
for i := 0; i < 5; i++ {
c, err := utils.JSONClone(a)
if err != nil {
t.Fatal(err)
}
t.Logf("%p, %#v", c, c)
}
}

View File

@@ -2,6 +2,7 @@ package cache
import (
"encoding/json"
"github.com/TeaOSLab/EdgeAdmin/internal/utils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
"github.com/iwind/TeaGo/actions"
@@ -28,7 +29,7 @@ func (this *CreatePopupAction) RunPost(params struct {
Must *actions.Must
}) {
cacheRef := &serverconfigs.HTTPCacheRef{}
var cacheRef = &serverconfigs.HTTPCacheRef{}
err := json.Unmarshal(params.CacheRefJSON, cacheRef)
if err != nil {
this.ErrorPage(err)
@@ -42,7 +43,13 @@ func (this *CreatePopupAction) RunPost(params struct {
this.Fail("请填写匹配条件分组")
}
err = cacheRef.Init()
this.Data["cacheRef"] = cacheRef
cacheRefClone, err := utils.JSONClone(cacheRef)
if err != nil {
this.Fail(err.Error())
}
err = cacheRefClone.(*serverconfigs.HTTPCacheRef).Init()
if err != nil {
this.ErrorPage(err)
return