From 255bd125c88d94e4cb57b09321507e0418b7ffac Mon Sep 17 00:00:00 2001 From: Adrian Gallagher Date: Sun, 5 Mar 2017 18:51:49 +1100 Subject: [PATCH] Move config.json to config.dat --- README.md | 2 +- config.go | 15 +++++++++++++-- config_encryption.go | 4 ++-- config_example.json => config_example.dat | 0 4 files changed, 16 insertions(+), 5 deletions(-) rename config_example.json => config_example.dat (100%) diff --git a/README.md b/README.md index 135bed98..58c70f66 100644 --- a/README.md +++ b/README.md @@ -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! diff --git a/config.go b/config.go index 70d37899..743c7c0f 100644 --- a/config.go +++ b/config.go @@ -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 @@ -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 { @@ -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 @@ -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 { diff --git a/config_encryption.go b/config_encryption.go index 8ae8e733..1145e560 100644 --- a/config_encryption.go +++ b/config_encryption.go @@ -36,7 +36,7 @@ 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 { @@ -44,7 +44,7 @@ func PromptForConfigKey() ([]byte, error) { } if len(cryptoKey) > 32 || len(cryptoKey) < 32 { - fmt.Println("Please re-enter a 32char key:") + fmt.Println("Please re-enter password (32 characters):") } } diff --git a/config_example.json b/config_example.dat similarity index 100% rename from config_example.json rename to config_example.dat