Files
fn-serverless/api/server/routes_delete.go
Pedro Nasser 32de7d5361 Improvements on API error, swagger and status code (#428)
* improvements on API error, swagger and status code

* missing validation

* removing typo

* fix if-within-if

* fix handle app delete
2016-12-13 19:18:52 -02:00

33 lines
852 B
Go

package server
import (
"context"
"net/http"
"path"
"github.com/gin-gonic/gin"
"github.com/iron-io/functions/api/models"
"github.com/iron-io/runner/common"
)
func (s *Server) handleRouteDelete(c *gin.Context) {
ctx := c.MustGet("ctx").(context.Context)
log := common.Logger(ctx)
appName := ctx.Value("appName").(string)
routePath := path.Clean(ctx.Value("routePath").(string))
if err := s.Datastore.RemoveRoute(ctx, appName, routePath); err != nil {
if err == models.ErrRoutesNotFound {
log.WithError(err).Debug(models.ErrRoutesRemoving)
c.JSON(http.StatusNotFound, simpleError(models.ErrRoutesNotFound))
} else {
log.WithError(err).Error(models.ErrRoutesRemoving)
c.JSON(http.StatusInternalServerError, simpleError(models.ErrRoutesRemoving))
}
return
}
c.JSON(http.StatusOK, gin.H{"message": "Route deleted"})
}