mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Clone of the trigger work to inject invoke urls into the annotations on a fn when it is returned from the server. Small changes to trigges code following code review of the fn code.
52 lines
1.0 KiB
Go
52 lines
1.0 KiB
Go
package server
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"github.com/fnproject/fn/api/models"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func (s *Server) handleFnList(c *gin.Context) {
|
|
ctx := c.Request.Context()
|
|
|
|
var filter models.FnFilter
|
|
filter.Cursor, filter.PerPage = pageParamsV2(c)
|
|
filter.AppID = c.Query("app_id")
|
|
filter.Name = c.Query("name")
|
|
|
|
fns, err := s.datastore.GetFns(ctx, &filter)
|
|
if err != nil {
|
|
handleErrorResponse(c, err)
|
|
return
|
|
}
|
|
|
|
// Annotate the outbound fns
|
|
|
|
// this is fairly cludgy bit hard to do in datastore middleware confidently
|
|
appCache := make(map[string]*models.App)
|
|
|
|
for idx, f := range fns.Items {
|
|
app, ok := appCache[f.AppID]
|
|
if !ok {
|
|
gotApp, err := s.Datastore().GetAppByID(ctx, f.AppID)
|
|
if err != nil {
|
|
handleErrorResponse(c, fmt.Errorf("failed to get app for fn %s", err))
|
|
return
|
|
}
|
|
app = gotApp
|
|
appCache[app.ID] = gotApp
|
|
}
|
|
|
|
newF, err := s.fnAnnotator.AnnotateFn(c, app, f)
|
|
if err != nil {
|
|
handleErrorResponse(c, err)
|
|
return
|
|
}
|
|
fns.Items[idx] = newF
|
|
}
|
|
|
|
c.JSON(http.StatusOK, fns)
|
|
}
|