forked from fasthall/cappa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtasks.go
52 lines (47 loc) · 982 Bytes
/
tasks.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
48
49
50
51
52
package main
import (
"github.com/fasthall/cappa/docker"
"github.com/fasthall/cappa/redis"
"github.com/gin-gonic/gin"
"github.com/nu7hatch/gouuid"
"net/http"
)
func tasksGET(c *gin.Context) {
task := c.Param("task")
image := redis.Get("tasks", task)
if image == "" {
c.JSON(http.StatusBadRequest, gin.H{
"status": http.StatusBadRequest,
"task": task,
"image": image,
})
} else {
c.JSON(http.StatusOK, gin.H{
"status": http.StatusOK,
"task": task,
"image": image,
})
}
}
func tasksPOST(c *gin.Context) {
image := c.PostForm("image")
uuid, err := uuid.NewV4()
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{
"message": "Cannot generate new key",
})
return
}
key := uuid.String()
redis.Set("tasks", key, image)
docker.Pull(image)
c.JSON(http.StatusOK, gin.H{
"status": http.StatusOK,
"uuid": key,
"image": image,
})
}
func tasksDELETE(c *gin.Context) {
task := c.Param("task")
redis.Del("tasks", task)
}