forked from thrasher-corp/gocryptotrader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configRoutes.go
69 lines (63 loc) · 1.66 KB
/
configRoutes.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
62
63
64
65
66
67
68
69
package main
import (
"encoding/json"
"net/http"
"github.com/thrasher-/gocryptotrader/config"
)
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) {
//Get the data from the request
decoder := json.NewDecoder(r.Body)
var responseData config.ConfigPost
jsonerr := decoder.Decode(&responseData)
if jsonerr != nil {
panic(jsonerr)
}
//Save change the settings
for x, _ := range bot.config.Exchanges {
for i := 0; i < len(responseData.Data.Exchanges); i++ {
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 := bot.config.SaveConfig()
if err != nil {
panic(err)
}
err = bot.config.LoadConfig()
if err != nil {
panic(err)
}
setupBotExchanges()
//Return response status
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)
}
}
var ConfigRoutes = Routes{
Route{
"GetAllSettings",
"GET",
"/config/all",
GetAllSettings,
},
Route{
"SaveAllSettings",
"POST",
"/config/all/save",
SaveAllSettings,
},
}