mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
34 lines
894 B
Go
34 lines
894 B
Go
package server
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"path"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/iron-io/functions/api"
|
|
"github.com/iron-io/functions/api/models"
|
|
"github.com/iron-io/runner/common"
|
|
)
|
|
|
|
func (s *Server) handleRouteGet(c *gin.Context) {
|
|
ctx := c.MustGet("ctx").(context.Context)
|
|
log := common.Logger(ctx)
|
|
|
|
appName := c.MustGet(api.AppName).(string)
|
|
routePath := path.Clean(c.MustGet(api.Path).(string))
|
|
|
|
route, err := s.Datastore.GetRoute(ctx, appName, routePath)
|
|
if err != nil && err != models.ErrRoutesNotFound {
|
|
log.WithError(err).Error(models.ErrRoutesGet)
|
|
c.JSON(http.StatusInternalServerError, simpleError(ErrInternalServerError))
|
|
return
|
|
} else if route == nil {
|
|
log.Debug(models.ErrRoutesNotFound)
|
|
c.JSON(http.StatusNotFound, simpleError(models.ErrRoutesNotFound))
|
|
return
|
|
}
|
|
|
|
c.JSON(http.StatusOK, routeResponse{"Successfully loaded route", route})
|
|
}
|