github.com/iron-io/functions@v0.0.0-20180820112432-d59d7d1c40b2/api/server/routes_list.go (about)

     1  package server
     2  
     3  import (
     4  	"context"
     5  	"net/http"
     6  
     7  	"github.com/gin-gonic/gin"
     8  	"github.com/iron-io/functions/api"
     9  	"github.com/iron-io/functions/api/models"
    10  )
    11  
    12  func (s *Server) handleRouteList(c *gin.Context) {
    13  	ctx := c.MustGet("ctx").(context.Context)
    14  
    15  	filter := &models.RouteFilter{}
    16  
    17  	if img := c.Query("image"); img != "" {
    18  		filter.Image = img
    19  	}
    20  
    21  	var routes []*models.Route
    22  	var err error
    23  	if appName, ok := c.MustGet(api.AppName).(string); ok && appName != "" {
    24  		routes, err = s.Datastore.GetRoutesByApp(ctx, appName, filter)
    25  	} else {
    26  		routes, err = s.Datastore.GetRoutes(ctx, filter)
    27  	}
    28  
    29  	if err != nil {
    30  		handleErrorResponse(c, err)
    31  		return
    32  	}
    33  
    34  	c.JSON(http.StatusOK, routesResponse{"Sucessfully listed routes", routes})
    35  }