Skip to content

Commit

Permalink
Fixed config values being saved using web interface.
Browse files Browse the repository at this point in the history
  • Loading branch information
thrasher- committed Aug 9, 2016
1 parent f21f2b8 commit dbc15b3
Showing 1 changed file with 12 additions and 19 deletions.
31 changes: 12 additions & 19 deletions configRoutes.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,49 +6,42 @@ import (
"net/http"
)

func getAllSettings(w http.ResponseWriter, r *http.Request) {

func GetAllSettings(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
w.WriteHeader(http.StatusOK)
if err := json.NewEncoder(w).Encode(bot.config); err != nil {
panic(err)
}
}

func saveAllSettings(w http.ResponseWriter, r *http.Request) {
func SaveAllSettings(w http.ResponseWriter, r *http.Request) {
//Get the data from the request
log.Println(r.Body)
decoder := json.NewDecoder(r.Body)
var responseData ConfigPost
jsonerr := decoder.Decode(&responseData)
if jsonerr != nil {
log.Println(jsonerr)
panic(jsonerr)
}
//Save change the settings
for _, exch := range bot.config.Exchanges {
for x, _ := range bot.config.Exchanges {
for i := 0; i < len(responseData.Data.Exchanges); i++ {
if responseData.Data.Exchanges[i].Name == exch.Name {
log.Println("Looking at exchange " + exch.Name)
log.Println("Enabled %s", responseData.Data.Exchanges[i].Enabled)
log.Println("Key " + responseData.Data.Exchanges[i].APIKey)
exch.Enabled = responseData.Data.Exchanges[i].Enabled
exch.APIKey = responseData.Data.Exchanges[i].APIKey
exch.APISecret = responseData.Data.Exchanges[i].APISecret
exch.EnabledPairs = responseData.Data.Exchanges[i].EnabledPairs
if responseData.Data.Exchanges[i].Name == bot.config.Exchanges[x].Name {
bot.config.Exchanges[x].Enabled = responseData.Data.Exchanges[i].Enabled
bot.config.Exchanges[x].APIKey = responseData.Data.Exchanges[i].APIKey
bot.config.Exchanges[x].APISecret = responseData.Data.Exchanges[i].APISecret
bot.config.Exchanges[x].EnabledPairs = responseData.Data.Exchanges[i].EnabledPairs
}
}
}
//Reload the configuration
err := SaveConfig()
if err != nil {
log.Println("Fatal error checking config values. Error:", err)
return
panic(err)
}
bot.config, err = ReadConfig()
if err != nil {
log.Println("Fatal error checking config values. Error:", err)
return
panic(err)
}
//Return response status
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
Expand All @@ -63,13 +56,13 @@ var configRoutes = Routes{
"GetAllSettings",
"GET",
"/config/all",
getAllSettings,
GetAllSettings,
},

Route{
"SaveAllSettings",
"POST",
"/config/all/save",
saveAllSettings,
SaveAllSettings,
},
}

0 comments on commit dbc15b3

Please sign in to comment.