Added support for hooks to customize behavior.

This commit is contained in:
Travis Reeder
2016-08-09 22:34:28 -07:00
parent 72a6d3aa5b
commit 8558d13f07
23 changed files with 324 additions and 42 deletions

View File

@@ -3,13 +3,16 @@ package server
import (
"net/http"
"github.com/Sirupsen/logrus"
"golang.org/x/net/context"
"github.com/gin-gonic/gin"
"github.com/iron-io/functions/api/models"
titancommon "github.com/iron-io/titan/common"
)
func handleAppCreate(c *gin.Context) {
log := c.MustGet("log").(logrus.FieldLogger)
ctx := c.MustGet("ctx").(context.Context)
log := titancommon.Logger(ctx)
wapp := &models.AppWrapper{}
@@ -32,12 +35,26 @@ func handleAppCreate(c *gin.Context) {
return
}
err = Api.FireBeforeAppUpdate(ctx, wapp.App)
if err != nil {
log.WithError(err).Errorln(models.ErrAppsCreate)
c.JSON(http.StatusInternalServerError, simpleError(err))
return
}
app, err := Api.Datastore.StoreApp(wapp.App)
if err != nil {
log.WithError(err).Debug(models.ErrAppsCreate)
log.WithError(err).Errorln(models.ErrAppsCreate)
c.JSON(http.StatusInternalServerError, simpleError(models.ErrAppsCreate))
return
}
err = Api.FireAfterAppUpdate(ctx, wapp.App)
if err != nil {
log.WithError(err).Errorln(models.ErrAppsCreate)
c.JSON(http.StatusInternalServerError, simpleError(err))
return
}
c.JSON(http.StatusOK, app)
}