mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-23 23:16:49 +00:00
Split up common.go, file path fixes and much more
This commit is contained in:
@@ -11,7 +11,7 @@ import "github.com/thrasher-/gocryptotrader/common"
|
||||
|
||||
testString := "aAaAa"
|
||||
|
||||
upper := common.StringToUpper(testString)
|
||||
upper := strings.ToUpper(testString)
|
||||
|
||||
// upper == "AAAAA"
|
||||
```
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"html/template"
|
||||
"log"
|
||||
"os"
|
||||
"runtime"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -118,7 +119,7 @@ func main() {
|
||||
codebasePaths = make(map[string]string)
|
||||
codebaseTemplatePath = make(map[string]string)
|
||||
codebaseReadme = make(map[string]readme)
|
||||
path = common.GetOSPathSlash()
|
||||
path = getOSPathSlash()
|
||||
|
||||
if err := getContributorList(); err != nil {
|
||||
log.Fatal("GoCryptoTrader: Exchange documentation tool GET error ", err)
|
||||
@@ -139,6 +140,16 @@ func main() {
|
||||
fmt.Println("\nTool finished")
|
||||
}
|
||||
|
||||
// getOSPathSlash returns the slash used by the operating systems
|
||||
// file system
|
||||
// TO-DO: Change all paths to not use this
|
||||
func getOSPathSlash() string {
|
||||
if runtime.GOOS == "windows" {
|
||||
return "\\"
|
||||
}
|
||||
return "/"
|
||||
}
|
||||
|
||||
// updateReadme iterates through codebase paths to check for readme files and either adds
|
||||
// or replaces with new readme files.
|
||||
func updateReadme() error {
|
||||
@@ -295,18 +306,18 @@ func getslashFromName(packageName string) string {
|
||||
}
|
||||
|
||||
var globS = []string{
|
||||
fmt.Sprintf("common_templates%s*", common.GetOSPathSlash()),
|
||||
fmt.Sprintf("communications_templates%s*", common.GetOSPathSlash()),
|
||||
fmt.Sprintf("config_templates%s*", common.GetOSPathSlash()),
|
||||
fmt.Sprintf("currency_templates%s*", common.GetOSPathSlash()),
|
||||
fmt.Sprintf("events_templates%s*", common.GetOSPathSlash()),
|
||||
fmt.Sprintf("exchanges_templates%s*", common.GetOSPathSlash()),
|
||||
fmt.Sprintf("portfolio_templates%s*", common.GetOSPathSlash()),
|
||||
fmt.Sprintf("root_templates%s*", common.GetOSPathSlash()),
|
||||
fmt.Sprintf("sub_templates%s*", common.GetOSPathSlash()),
|
||||
fmt.Sprintf("testdata_templates%s*", common.GetOSPathSlash()),
|
||||
fmt.Sprintf("tools_templates%s*", common.GetOSPathSlash()),
|
||||
fmt.Sprintf("web_templates%s*", common.GetOSPathSlash()),
|
||||
fmt.Sprintf("common_templates%s*", getOSPathSlash()),
|
||||
fmt.Sprintf("communications_templates%s*", getOSPathSlash()),
|
||||
fmt.Sprintf("config_templates%s*", getOSPathSlash()),
|
||||
fmt.Sprintf("currency_templates%s*", getOSPathSlash()),
|
||||
fmt.Sprintf("events_templates%s*", getOSPathSlash()),
|
||||
fmt.Sprintf("exchanges_templates%s*", getOSPathSlash()),
|
||||
fmt.Sprintf("portfolio_templates%s*", getOSPathSlash()),
|
||||
fmt.Sprintf("root_templates%s*", getOSPathSlash()),
|
||||
fmt.Sprintf("sub_templates%s*", getOSPathSlash()),
|
||||
fmt.Sprintf("testdata_templates%s*", getOSPathSlash()),
|
||||
fmt.Sprintf("tools_templates%s*", getOSPathSlash()),
|
||||
fmt.Sprintf("web_templates%s*", getOSPathSlash()),
|
||||
}
|
||||
|
||||
// addTemplates adds all the template files
|
||||
|
||||
@@ -7,12 +7,13 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
|
||||
"github.com/thrasher-/gocryptotrader/currency"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges/assets"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/thrasher-/gocryptotrader/common"
|
||||
"github.com/thrasher-/gocryptotrader/config"
|
||||
"github.com/thrasher-/gocryptotrader/currency"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges/assets"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -22,9 +23,9 @@ const (
|
||||
packageMain = "%s.go"
|
||||
packageReadme = "README.md"
|
||||
|
||||
exchangePackageLocation = "..%s..%sexchanges%s"
|
||||
exchangeLocation = "..%s..%sexchange.go"
|
||||
exchangeConfigPath = "..%s..%stestdata%sconfigtest.json"
|
||||
exchangePackageLocation = "../../exchanges"
|
||||
exchangeLocation = "../../exchange.go"
|
||||
exchangeConfigPath = "../../testdata/configtest.json"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -84,9 +85,9 @@ func main() {
|
||||
log.Fatal("GoCryptoTrader: Exchange templating tool stopped...")
|
||||
}
|
||||
|
||||
newExchangeName = common.StringToLower(newExchangeName)
|
||||
newExchangeName = strings.ToLower(newExchangeName)
|
||||
v := newExchangeName[:1]
|
||||
capName := common.StringToUpper(v) + newExchangeName[1:]
|
||||
capName := strings.ToUpper(v) + newExchangeName[1:]
|
||||
|
||||
exch := exchange{
|
||||
Name: newExchangeName,
|
||||
@@ -97,18 +98,14 @@ func main() {
|
||||
FIX: fixSupport,
|
||||
}
|
||||
|
||||
osPathSlash := common.GetOSPathSlash()
|
||||
exchangeJSON := fmt.Sprintf(exchangeConfigPath, osPathSlash, osPathSlash, osPathSlash)
|
||||
|
||||
configTestFile := config.GetConfig()
|
||||
err = configTestFile.LoadConfig(exchangeJSON)
|
||||
err = configTestFile.LoadConfig(exchangeConfigPath)
|
||||
if err != nil {
|
||||
log.Fatal("GoCryptoTrader: Exchange templating configuration retrieval error ", err)
|
||||
}
|
||||
// NOTE need to nullify encrypt configuration
|
||||
|
||||
var configTestExchanges []string
|
||||
|
||||
for x := range configTestFile.Exchanges {
|
||||
configTestExchanges = append(configTestExchanges, configTestFile.Exchanges[x].Name)
|
||||
}
|
||||
@@ -137,18 +134,12 @@ func main() {
|
||||
log.Fatal("GoCryptoTrader: Exchange templating configuration error - cannot save")
|
||||
}
|
||||
|
||||
exchangeDirectory = fmt.Sprintf(
|
||||
exchangePackageLocation+newExchangeName+"%s",
|
||||
osPathSlash,
|
||||
osPathSlash,
|
||||
osPathSlash,
|
||||
osPathSlash)
|
||||
|
||||
exchangeTest = fmt.Sprintf(exchangeDirectory+packageTests, newExchangeName)
|
||||
exchangeTypes = fmt.Sprintf(exchangeDirectory+packageTypes, newExchangeName)
|
||||
exchangeWrapper = fmt.Sprintf(exchangeDirectory+packageWrapper, newExchangeName)
|
||||
exchangeMain = fmt.Sprintf(exchangeDirectory+packageMain, newExchangeName)
|
||||
exchangeReadme = exchangeDirectory + packageReadme
|
||||
exchangeDirectory = filepath.Join(exchangePackageLocation, newExchangeName)
|
||||
exchangeTest = filepath.Join(exchangeDirectory, fmt.Sprintf(packageTests, newExchangeName))
|
||||
exchangeTypes = filepath.Join(exchangeDirectory, fmt.Sprintf(packageTypes, newExchangeName))
|
||||
exchangeWrapper = filepath.Join(exchangeDirectory, fmt.Sprintf(packageWrapper, newExchangeName))
|
||||
exchangeMain = filepath.Join(exchangeDirectory, fmt.Sprintf(packageMain, newExchangeName))
|
||||
exchangeReadme = filepath.Join(exchangeDirectory, packageReadme)
|
||||
|
||||
err = os.Mkdir(exchangeDirectory, 0700)
|
||||
if err != nil {
|
||||
|
||||
@@ -60,9 +60,9 @@ func ({{.Variable}} *{{.CapitalName}}) Setup(exch *config.ExchangeConfig) error
|
||||
{{.Variable}}.SetHTTPClientUserAgent(exch.HTTPUserAgent)
|
||||
{{.Variable}}.Verbose = exch.Verbose
|
||||
{{.Variable}}.Websocket.SetWsStatusAndConnection(exch.Features.Enabled.Websocket)
|
||||
{{.Variable}}.BaseCurrencies = common.SplitStrings(exch.BaseCurrencies, ",")
|
||||
{{.Variable}}.AvailablePairs = common.SplitStrings(exch.AvailablePairs, ",")
|
||||
{{.Variable}}.EnabledPairs = common.SplitStrings(exch.EnabledPairs, ",")
|
||||
{{.Variable}}.BaseCurrencies = strings.Split(exch.BaseCurrencies, ",")
|
||||
{{.Variable}}.AvailablePairs = strings.Split(exch.AvailablePairs, ",")
|
||||
{{.Variable}}.EnabledPairs = strings.Split(exch.EnabledPairs, ",")
|
||||
err := {{.Variable}}.SetCurrencyPairFormat()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
|
||||
Reference in New Issue
Block a user