package server import ( "net/http" "github.com/Sirupsen/logrus" "github.com/gin-gonic/gin" "github.com/iron-io/functions/api/models" ) func handleAppCreate(c *gin.Context) { log := c.MustGet("log").(logrus.FieldLogger) wapp := &models.AppWrapper{} err := c.BindJSON(wapp) if err != nil { log.WithError(err).Debug(models.ErrInvalidJSON) c.JSON(http.StatusBadRequest, simpleError(models.ErrInvalidJSON)) return } if wapp.App == nil { log.Debug(models.ErrAppsMissingNew) c.JSON(http.StatusBadRequest, simpleError(models.ErrAppsMissingNew)) return } if err := wapp.Validate(); err != nil { log.Error(err) c.JSON(http.StatusInternalServerError, simpleError(err)) return } app, err := Api.Datastore.StoreApp(wapp.App) if err != nil { log.WithError(err).Debug(models.ErrAppsCreate) c.JSON(http.StatusInternalServerError, simpleError(models.ErrAppsCreate)) return } c.JSON(http.StatusOK, app) }