mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
* fix datastore error inexistent app * fix get route error handling * fix API errors handling and tests
36 lines
739 B
Go
36 lines
739 B
Go
package server
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/iron-io/functions/api"
|
|
"github.com/iron-io/functions/api/models"
|
|
)
|
|
|
|
func (s *Server) handleRouteList(c *gin.Context) {
|
|
ctx := c.MustGet("ctx").(context.Context)
|
|
|
|
filter := &models.RouteFilter{}
|
|
|
|
if img := c.Query("image"); img != "" {
|
|
filter.Image = img
|
|
}
|
|
|
|
var routes []*models.Route
|
|
var err error
|
|
if appName, ok := c.MustGet(api.AppName).(string); ok && appName != "" {
|
|
routes, err = s.Datastore.GetRoutesByApp(ctx, appName, filter)
|
|
} else {
|
|
routes, err = s.Datastore.GetRoutes(ctx, filter)
|
|
}
|
|
|
|
if err != nil {
|
|
handleErrorResponse(c, err)
|
|
return
|
|
}
|
|
|
|
c.JSON(http.StatusOK, routesResponse{"Sucessfully listed routes", routes})
|
|
}
|