mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
48 lines
1.1 KiB
Go
48 lines
1.1 KiB
Go
package server
|
|
|
|
import (
|
|
"encoding/base64"
|
|
"net/http"
|
|
|
|
"github.com/fnproject/fn/api"
|
|
"github.com/fnproject/fn/api/models"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func (s *Server) handleRouteList(c *gin.Context) {
|
|
ctx := c.Request.Context()
|
|
|
|
appName := c.MustGet(api.AppName).(string)
|
|
|
|
var filter models.RouteFilter
|
|
filter.Image = c.Query("image")
|
|
// filter.PathPrefix = c.Query("path_prefix") TODO not hooked up
|
|
filter.Cursor, filter.PerPage = pageParams(c, true)
|
|
|
|
routes, err := s.Datastore().GetRoutesByApp(ctx, appName, &filter)
|
|
|
|
// if there are no routes for the app, check if the app exists to return
|
|
// 404 if it does not
|
|
// TODO this should be done in front of this handler to even get here...
|
|
if err == nil && len(routes) == 0 {
|
|
_, err = s.Datastore().GetApp(ctx, appName)
|
|
}
|
|
|
|
if err != nil {
|
|
handleErrorResponse(c, err)
|
|
return
|
|
}
|
|
|
|
var nextCursor string
|
|
if len(routes) > 0 && len(routes) == filter.PerPage {
|
|
last := []byte(routes[len(routes)-1].Path)
|
|
nextCursor = base64.RawURLEncoding.EncodeToString(last)
|
|
}
|
|
|
|
c.JSON(http.StatusOK, routesResponse{
|
|
Message: "Successfully listed routes",
|
|
NextCursor: nextCursor,
|
|
Routes: routes,
|
|
})
|
|
}
|