Added route for updating server-settings.json file

This commit is contained in:
majormjr 2016-10-11 11:38:25 -04:00
parent c4304e9b51
commit 17a9c7c8af
2 changed files with 36 additions and 1 deletions

View File

@ -931,7 +931,7 @@ func RemoveUser(w http.ResponseWriter, r *http.Request) {
}
}
// Return JSON response of config.ini file
// Return JSON response of server-settings.json file
func GetServerSettings(w http.ResponseWriter, r *http.Request) {
resp := JSONResponse{
Success: false,
@ -948,3 +948,33 @@ func GetServerSettings(w http.ResponseWriter, r *http.Request) {
log.Printf("Sent server settings response")
}
func UpdateServerSettings(w http.ResponseWrite, r *http.Request) {
resp := JSONResponse{
Success: false,
}
w.Header().Set("Content-Type", "application/json;charset=UTF-8")
switch r.Method {
case "GET":
log.Printf("GET not supported for add user handler")
resp.Data = "Unsupported method"
resp.Success = false
if err := json.NewEncoder(w).Encode(resp); err != nil {
log.Printf("Error adding user: %s", err)
}
case "POST":
body, err := ioutil.ReadAll(r.Body)
if err != nil {
log.Printf("Error in reading server settings POST: %s", err)
resp.Data = fmt.Sprintf("Error in updating settings: %s", err)
resp.Success = false
if err := json.NewEncoder(w).Encode(resp); err != nil {
log.Printf("Error updating settings: %s", err)
}
return
}
log.Printf("Received settings JSON: %s", body)
}
}

View File

@ -225,5 +225,10 @@ var apiRoutes = Routes{
"GET",
"/settings",
GetServerSettings,
}, {
"UpdateServerSettings",
"POST",
"/settings/update",
UpdateServerSettings,
},
}