func (ctl *AlertController) postAddAlertsPolicyAction(c *gin.Context) { var form models.AlertPolicyForm if err := c.Bind(&form); err != nil { c.AbortWithStatus(http.StatusBadRequest) return } if err := form.Validate(); err != nil { c.HTML(http.StatusOK, "alert_policy_add.html", map[string]interface{}{ "NagiosPlugins": models.NagiosPlugins, "errors": err.Errors, "form": form, }) return } ap := models.AlertPolicyMapper.Create(&form) if err := models.AlertPolicyMapper.Save(ap); err != nil { panic(err) } c.Redirect(http.StatusFound, "/alerts-policies") }
func (ctl *AlertController) getEditAlertsPolicyAction(c *gin.Context) { ap, err := models.AlertPolicyMapper.FetchOne(c.Param("id")) if err != nil { panic(err) } if ap == nil { c.Redirect(http.StatusFound, "/alerts-policies") return } var form models.AlertPolicyForm form.Hydrate(ap) log.Println("interval", form.Interval) c.HTML(http.StatusOK, "alert_policy_add.html", map[string]interface{}{ "NagiosPlugins": models.NagiosPlugins, "form": form, "policy": ap, }) }