-
Notifications
You must be signed in to change notification settings - Fork 2
/
api_actions.go
46 lines (38 loc) · 927 Bytes
/
api_actions.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
package neocortex
import (
"net/http"
"github.com/gin-gonic/gin"
)
func (api *API) registerActionsAPI(r *gin.RouterGroup) {
r.POST("/actions/env/:name", func(c *gin.Context) {
name := c.Param("name")
type bind struct {
Value string `json:"value"`
}
value := new(bind)
err := c.BindJSON(value)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
err = api.repository.SetActionVar(name, value.Value)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
c.JSON(http.StatusOK, gin.H{
"data": value,
})
})
r.GET("/actions/env/:name", func(c *gin.Context) {
name := c.Param("name")
value, err := api.repository.GetActionVar(name)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
c.JSON(http.StatusOK, gin.H{
"data": value,
})
})
}