Skip to content

Commit

Permalink
Move config.json to config.dat
Browse files Browse the repository at this point in the history
  • Loading branch information
thrasher- committed Mar 5, 2017
1 parent fed5367 commit 255bd12
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Please feel free to submit any pull requests or suggest any desired features to
Download Go from https://golang.org/dl/
Using a terminal, type go get github.com/thrasher-/gocryptotrader
Change directory to the package directory, then type go install.
Copy config_example.json to config.json.
Copy config_example.dat to config.dat.
Make any neccessary changes to the config file.
Run the application!

Expand Down
15 changes: 13 additions & 2 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import (
"fmt"
"io/ioutil"
"log"
"os"
"strconv"
"time"
)

const (
CONFIG_FILE = "config.json"
CONFIG_FILE = "config.dat"
OLD_CONFIG_FILE = "config.json"

CONFIG_FILE_ENCRYPTION_PROMPT = 0
CONFIG_FILE_ENCRYPTION_ENABLED = 1
Expand All @@ -36,6 +38,7 @@ var (
WarningWebserverListenAddressInvalid = "WARNING -- Webserver support disabled due to invalid listen address."
WarningWebserverRootWebFolderNotFound = "WARNING -- Webserver support disabled due to missing web folder."
WarningExchangeAuthAPIDefaultOrEmptyValues = "WARNING -- Exchange %s: Authenticated API support disabled due to default/empty APIKey/Secret/ClientID values."
RenamingConfigFile = "Renaming config file %s to %s."
)

type Webserver struct {
Expand Down Expand Up @@ -196,6 +199,15 @@ func CheckWebserverValues() error {
}

func ReadConfig() error {
_, err := ioutil.ReadFile(OLD_CONFIG_FILE)
if err == nil {
err = os.Rename(OLD_CONFIG_FILE, CONFIG_FILE)
if err != nil {
return err
}
log.Printf(RenamingConfigFile+"\n", OLD_CONFIG_FILE, CONFIG_FILE)
}

file, err := ioutil.ReadFile(CONFIG_FILE)
if err != nil {
return err
Expand Down Expand Up @@ -237,7 +249,6 @@ func ReadConfig() error {
}

func SaveConfig() error {
log.Println("Saving config.")
payload, err := json.MarshalIndent(bot.config, "", " ")

if bot.config.EncryptConfig == CONFIG_FILE_ENCRYPTION_ENABLED {
Expand Down
4 changes: 2 additions & 2 deletions config_encryption.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ func PromptForConfigKey() ([]byte, error) {
var cryptoKey []byte

for len(cryptoKey) != 32 {
log.Println("Please enter your 32 character AES key:")
log.Println("Enter password (32 characters):")

_, err := fmt.Scanln(&cryptoKey)
if err != nil {
return nil, err
}

if len(cryptoKey) > 32 || len(cryptoKey) < 32 {
fmt.Println("Please re-enter a 32char key:")
fmt.Println("Please re-enter password (32 characters):")
}
}

Expand Down
File renamed without changes.

0 comments on commit 255bd12

Please sign in to comment.