-
Notifications
You must be signed in to change notification settings - Fork 405
/
fns_create.go
47 lines (39 loc) · 916 Bytes
/
fns_create.go
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
36
37
38
39
40
41
42
43
44
45
46
47
package server
import (
"net/http"
"github.com/fnproject/fn/api/common"
"github.com/fnproject/fn/api/models"
"github.com/gin-gonic/gin"
)
func (s *Server) handleFnCreate(c *gin.Context) {
ctx := c.Request.Context()
log := common.Logger(ctx)
fn := &models.Fn{}
err := c.BindJSON(fn)
if err != nil {
if !models.IsAPIError(err) {
err = models.ErrInvalidJSON
}
handleErrorResponse(c, err)
return
}
fn.SetDefaults()
fnCreated, err := s.datastore.InsertFn(ctx, fn)
if err != nil {
handleErrorResponse(c, err)
return
}
app, err := s.datastore.GetAppByID(ctx, fnCreated.AppID)
if err != nil {
log.Debugln("Failed to lookup app.")
c.JSON(http.StatusOK, fnCreated)
return
}
fnAnnotated, err := s.fnAnnotator.AnnotateFn(c, app, fnCreated)
if err != nil {
log.Debugln("Failed to annotate fn")
c.JSON(http.StatusOK, fnCreated)
return
}
c.JSON(http.StatusOK, fnAnnotated)
}