Files
EdgeAdmin/internal/web/actions/default/servers/server/settings/conds/addCondPopup.go

44 lines
1.1 KiB
Go
Raw Normal View History

2020-09-29 11:28:39 +08:00
package conds
import (
"encoding/json"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/conds/condutils"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
"github.com/iwind/TeaGo/actions"
)
type AddCondPopupAction struct {
actionutils.ParentAction
}
func (this *AddCondPopupAction) Init() {
}
func (this *AddCondPopupAction) RunGet(params struct{}) {
this.Data["components"] = condutils.ReadAllAvailableCondTypes()
this.Show()
}
func (this *AddCondPopupAction) RunPost(params struct {
CondType string
CondJSON []byte
Must *actions.Must
}) {
condConfig := &shared.HTTPRequestCond{}
err := json.Unmarshal(params.CondJSON, condConfig)
if err != nil {
2021-06-09 17:14:31 +08:00
this.Fail("解析条件设置时发生了错误:" + err.Error() + ", JSON: " + string(params.CondJSON))
2020-09-29 11:28:39 +08:00
}
err = condConfig.Init()
if err != nil {
this.Fail("校验条件设置时失败:" + err.Error())
}
2020-09-29 11:28:39 +08:00
condConfig.Type = params.CondType
this.Data["cond"] = condConfig
this.Success()
}