forked from iron-io/functions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroutes_list.go
More file actions
35 lines (27 loc) · 789 Bytes
/
routes_list.go
File metadata and controls
35 lines (27 loc) · 789 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package server
import (
"context"
"net/http"
"github.com/ZejunZhou/Ironfunctions-ServerlessResearch/api"
"github.com/ZejunZhou/Ironfunctions-ServerlessResearch/api/models"
"github.com/gin-gonic/gin"
)
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})
}