Skip to content
This repository was archived by the owner on Feb 3, 2019. It is now read-only.

Commit fc29638

Browse files
author
deissh
committed
исправил ошибки + переделал запуск и удлаение функций
1 parent a50d6e3 commit fc29638

File tree

4 files changed

+11
-27
lines changed

4 files changed

+11
-27
lines changed

pkg/manager/run.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"golang.org/x/net/context"
99
)
1010

11-
func (c *Core) Create(info typings.FunctionInfo) error {
11+
func (c *Core) Create(info typings.FunctionInfo) (string, error) {
1212
// получаем контейнер
1313
//_, err := c.client.ImagePull(
1414
// context.Background(),
@@ -30,7 +30,6 @@ func (c *Core) Create(info typings.FunctionInfo) error {
3030
},
3131
Labels: map[string]string{
3232
"lambda.active": "true",
33-
"lambda.uuid": info.Uuid,
3433
"lambda.port": "8080",
3534
},
3635
Env: []string{
@@ -51,7 +50,7 @@ func (c *Core) Create(info typings.FunctionInfo) error {
5150
nil,
5251
info.Uuid)
5352
if err != nil {
54-
return err
53+
return "", err
5554
}
5655

5756
// запускаем контейнер
@@ -63,5 +62,5 @@ func (c *Core) Create(info typings.FunctionInfo) error {
6362
panic(err)
6463
}
6564

66-
return nil
65+
return resp.ID, nil
6766
}

pkg/server/create.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ func createHandler(m manager.Core) gin.HandlerFunc {
2121
return
2222
}
2323

24-
if err := m.Create(body); err != nil {
24+
uuid, err := m.Create(body)
25+
if err != nil {
2526
c.JSON(http.StatusBadRequest, gin.H{
2627
"error": err.Error(),
2728
})
@@ -30,7 +31,7 @@ func createHandler(m manager.Core) gin.HandlerFunc {
3031
}
3132

3233
c.JSON(200, gin.H{
33-
"message": "ok",
34+
"uuid": uuid,
3435
})
3536
}
3637
}

pkg/server/delete.go

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,13 @@ func deleteHandler(m manager.Core) gin.HandlerFunc {
1111
return func(c *gin.Context) {
1212
uuid := c.Param("uuid")
1313

14-
containers, err := m.GetActive()
15-
if err != nil {
14+
if err := m.Stop(uuid); err != nil {
15+
log.Println(err)
1616
c.JSON(http.StatusInternalServerError, gin.H{
17-
"error": err.Error(),
17+
"error": "function uuid not founded",
1818
})
19-
log.Println(err)
20-
return
2119
}
2220

23-
for _, cont := range containers {
24-
for _, name := range cont.Names {
25-
// fix docker name
26-
if name == "/"+uuid {
27-
if err := m.Stop(cont.ID); err != nil {
28-
log.Println(err)
29-
c.JSON(http.StatusInternalServerError, gin.H{
30-
"error": err.Error(),
31-
})
32-
}
33-
34-
c.JSON(http.StatusOK, gin.H{})
35-
}
36-
}
37-
}
21+
c.JSON(http.StatusOK, gin.H{})
3822
}
3923
}

pkg/typings/function.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package typings
22

33
type FunctionInfo struct {
44
Name string `json:"name" binding:"required"`
5-
Uuid string `json:"uuid" binding:"required"`
5+
Uuid string `json:"uuid"`
66
Runtime struct {
77
Executor string `json:"executor" binding:"required"`
88
Cmd string `json:"cmd"`

0 commit comments

Comments
 (0)