func (cc *ConfigController) postConfig(c *gin.Context) { app, err := cc.getApp(c) if err != nil { c.JSON(http.StatusNotFound, err) return } var form models.ConfigCreateForm if err := c.Bind(&form); err != nil { c.AbortWithStatus(http.StatusBadRequest) return } if err := form.Validate(); err != nil { c.JSON(http.StatusBadRequest, err) return } conf := models.ConfigMapper.Create(app, &form) if err := models.ConfigMapper.Save(conf); err != nil { panic(err) } c.JSON(http.StatusCreated, conf) }
func (ctl *LogfileController) getAddLogfileAction(c *gin.Context) { appId := c.Param("app_id") application := ctl.getApplication(c, appId) if application == nil { return } var form models.ConfigCreateForm form.Notify = "restart:" + application.Name form.Enabled = true c.HTML(http.StatusOK, "logfile_add.html", map[string]interface{}{ "application": application, "form": form, }) }
/** * 1 - add a configuration */ func (ctl *ConfigurationController) postAddConfigurationAction(c *gin.Context) { appId := c.Param("app_id") application := ctl.getApplication(c, appId) if application == nil { return } var form models.ConfigCreateForm if err := c.Bind(&form); err != nil { c.AbortWithStatus(http.StatusBadRequest) return } // Workaround for bool field, because http form only send string // The value is "on" for true, and "" for false form.Enabled = c.PostForm("enabled") == "on" if err := form.Validate(); err != nil { c.HTML(http.StatusOK, "configuration_add.html", map[string]interface{}{ "errors": err.Errors, "application": application, "form": form, }) return } config := models.ConfigMapper.Create(application, &form) if err := models.ConfigMapper.Save(config); err != nil { panic(err) } c.Redirect(http.StatusFound, "/application/show/"+application.Name) }