mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
41 lines
893 B
Go
41 lines
893 B
Go
package server
|
|
|
|
import (
|
|
"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()
|
|
|
|
filter := &models.RouteFilter{}
|
|
|
|
if img := c.Query("image"); img != "" {
|
|
filter.Image = img
|
|
}
|
|
|
|
var routes []*models.Route
|
|
var err error
|
|
appName, exists := c.Get(api.AppName)
|
|
name, ok := appName.(string)
|
|
if exists && ok && name != "" {
|
|
routes, err = s.Datastore.GetRoutesByApp(ctx, name, filter)
|
|
// if there are no routes for the app, check if the app exists to return 404 if it does not
|
|
if len(routes) == 0 {
|
|
_, err = s.Datastore.GetApp(ctx, name)
|
|
}
|
|
} else {
|
|
routes, err = s.Datastore.GetRoutes(ctx, filter)
|
|
}
|
|
|
|
if err != nil {
|
|
handleErrorResponse(c, err)
|
|
return
|
|
}
|
|
|
|
c.JSON(http.StatusOK, routesResponse{"Successfully listed routes", routes})
|
|
}
|