/
config_vars.go
61 lines (47 loc) · 1.28 KB
/
config_vars.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
53
54
55
56
57
58
59
60
61
package controllers
import (
"encoding/json"
"net/http"
"github.com/gorilla/mux"
"github.com/unrolled/render"
"github.com/spesnova/iruka/registry"
"github.com/spesnova/iruka/schema"
)
type ConfigVarsController struct {
*registry.Registry
*render.Render
}
func NewConfigVarsController(reg *registry.Registry, ren *render.Render) ConfigVarsController {
return ConfigVarsController{reg, ren}
}
func (c *ConfigVarsController) Update(rw http.ResponseWriter, r *http.Request) {
defer r.Body.Close()
vars := mux.Vars(r)
appIdentity := vars["appIdentity"]
var opts schema.ConfigVars
err := json.NewDecoder(r.Body).Decode(&opts)
if err != nil {
c.JSON(rw, http.StatusInternalServerError, "error")
return
}
configVars, err := c.UpdateConfigVars(appIdentity, opts)
if err != nil {
c.JSON(rw, http.StatusInternalServerError, "error")
return
}
c.JSON(rw, http.StatusCreated, configVars)
}
func (c *ConfigVarsController) Info(rw http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
appIdentity := vars["appIdentity"]
configVars, err := c.ConfigVars(appIdentity)
if err != nil {
c.JSON(rw, http.StatusInternalServerError, "error")
return
}
if len(configVars) == 0 {
c.JSON(rw, http.StatusOK, schema.ConfigVars{})
return
}
c.JSON(rw, http.StatusOK, configVars)
}