fix the logic for add HTTPRuleRewrite model

This commit is contained in:
med1tator 2022-01-06 10:03:48 +08:00
parent 1d334ad4c1
commit 9168b0d58c

View File

@ -325,12 +325,10 @@ func (h *HTTPRuleRewriteDaoTmpl) AddModel(mo model.Interface) error {
return fmt.Errorf("can't not convert %s to *model.HTTPRuleRewrite", reflect.TypeOf(mo).String())
}
var oldHTTPRuleRewrite model.HTTPRuleRewrite
if ok := h.DB.Where("uuid = ?", httpRuleRewrite.UUID).Find(&oldHTTPRuleRewrite).RecordNotFound(); ok {
if err := h.DB.Create(httpRuleRewrite).Error; err != nil {
return err
}
if ok := h.DB.Where("uuid = ?", httpRuleRewrite.UUID).Find(&oldHTTPRuleRewrite).RecordNotFound(); !ok {
return fmt.Errorf("HTTPRuleRewrite already exists based on uuid(%s)", httpRuleRewrite.UUID)
}
return fmt.Errorf("HTTPRuleRewrite already exists based on uuid(%s)", httpRuleRewrite.UUID)
return h.DB.Create(httpRuleRewrite).Error
}
//UpdateModel -