Plugins settings working

Former-commit-id: bf510f9474baf82d86f56447595f11df8bab37af [formerly f66ec9d1e271bf7167086986e82002bf7007f184] [formerly 6df52279a22f6d91503b74e7c6f18f2c6a825207 [formerly b86d9b16b9]]
Former-commit-id: 3d2b4d2c4e7004c8e704044d669eec07418825a5 [formerly 18ee8c63b9b50dc26c36e0acdb9bda8cc7069d1e]
Former-commit-id: b9d487d62ea901fc627e74a50b98666f6831fd4e
This commit is contained in:
Henrique Dias
2017-07-18 14:43:16 +01:00
parent 66382a7f6b
commit 9c205c928e
6 changed files with 142 additions and 11 deletions

View File

@@ -4,6 +4,8 @@ import (
"encoding/json"
"errors"
"net/http"
"github.com/mitchellh/mapstructure"
)
func commandsHandler(c *RequestContext, w http.ResponseWriter, r *http.Request) (int, error) {
@@ -78,6 +80,25 @@ func pluginsPutHandler(c *RequestContext, w http.ResponseWriter, r *http.Request
return http.StatusBadGateway, errors.New("Empty request body")
}
// TODO
var raw map[string]map[string]interface{}
// Parses the user and checks for error.
err := json.NewDecoder(r.Body).Decode(&raw)
if err != nil {
return http.StatusBadRequest, err
}
for name, plugin := range raw {
err = mapstructure.Decode(plugin, c.FM.Plugins[name])
if err != nil {
return http.StatusInternalServerError, err
}
err = c.FM.db.Set("plugins", name, c.FM.Plugins[name])
if err != nil {
return http.StatusInternalServerError, err
}
}
return http.StatusOK, nil
}