mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-19 23:16:48 +00:00
Fixed config values being saved using web interface.
This commit is contained in:
@@ -6,8 +6,7 @@ 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 {
|
||||
@@ -15,40 +14,34 @@ func getAllSettings(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
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")
|
||||
@@ -63,13 +56,13 @@ var configRoutes = Routes{
|
||||
"GetAllSettings",
|
||||
"GET",
|
||||
"/config/all",
|
||||
getAllSettings,
|
||||
GetAllSettings,
|
||||
},
|
||||
|
||||
Route{
|
||||
"SaveAllSettings",
|
||||
"POST",
|
||||
"/config/all/save",
|
||||
saveAllSettings,
|
||||
SaveAllSettings,
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user