mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 15:09:42 +00:00
engine: Adds shutdown method to exchange manager and unload all exchanges when engine is stopped (#1112)
* engine: shutdown and unload exchange when engine is stopped * linter: fixes * engine/exchMan: add nil check * engine/exchanges: add shutdown method to exchanges, rm len check lock not needed, expanded code coverage, address some nits * exchMan: report all failed shutdowns across exchanges, implement timer and monitoring routines. * exchMan: improve shutdown sequence and aloc. * further improvement * exchman: log from warn to error * websockconnection: Suppress error return when closure is caused by library * linter: fix * fix racies * add note on why not parallel tests * glorious: nits * spelling kween * thrasher: nits * engine: change print of setting using reflection, I keep forgetting to implement this so program around forgetfulness * engine/exchange_management: remove wait group and just rely on intermediary lock * glorious: nits * Update common/common.go Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io> * Update main.go Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io> --------- Co-authored-by: Ryan O'Hara-Reid <ryan.oharareid@thrasher.io> Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io>
This commit is contained in:
@@ -19,6 +19,7 @@ import (
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
"unicode"
|
||||
|
||||
"github.com/thrasher-corp/gocryptotrader/common/file"
|
||||
"github.com/thrasher-corp/gocryptotrader/log"
|
||||
@@ -412,6 +413,37 @@ func SplitStringSliceByLimit(in []string, limit uint) [][]string {
|
||||
return sliceSlice
|
||||
}
|
||||
|
||||
// AddPaddingOnUpperCase adds padding to a string when detecting an upper case letter. If
|
||||
// there are multiple upper case items like `ThisIsHTTPExample`, it will only
|
||||
// pad between like this `This Is HTTP Example`.
|
||||
func AddPaddingOnUpperCase(s string) string {
|
||||
if s == "" {
|
||||
return ""
|
||||
}
|
||||
var result []string
|
||||
left := 0
|
||||
for x := 0; x < len(s); x++ {
|
||||
if x == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
if unicode.IsUpper(rune(s[x])) {
|
||||
if !unicode.IsUpper(rune(s[x-1])) {
|
||||
result = append(result, s[left:x])
|
||||
left = x
|
||||
}
|
||||
} else if x > 1 && unicode.IsUpper(rune(s[x-1])) {
|
||||
if s[left:x-1] == "" {
|
||||
continue
|
||||
}
|
||||
result = append(result, s[left:x-1])
|
||||
left = x - 1
|
||||
}
|
||||
}
|
||||
result = append(result, s[left:])
|
||||
return strings.Join(result, " ")
|
||||
}
|
||||
|
||||
// InArray checks if _val_ belongs to _array_
|
||||
func InArray(val, array interface{}) (exists bool, index int) {
|
||||
exists = false
|
||||
|
||||
@@ -583,6 +583,37 @@ func TestSplitStringSliceByLimit(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAddPaddingOnUpperCase(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
testCases := []struct {
|
||||
Supplied string
|
||||
Expected string
|
||||
}{
|
||||
{
|
||||
// empty
|
||||
},
|
||||
{
|
||||
Supplied: "ExpectedHTTPRainbow",
|
||||
Expected: "Expected HTTP Rainbow",
|
||||
},
|
||||
{
|
||||
Supplied: "SmellyCatSmellsBad",
|
||||
Expected: "Smelly Cat Smells Bad",
|
||||
},
|
||||
{
|
||||
Supplied: "Gronk",
|
||||
Expected: "Gronk",
|
||||
},
|
||||
}
|
||||
|
||||
for x := range testCases {
|
||||
if received := AddPaddingOnUpperCase(testCases[x].Supplied); received != testCases[x].Expected {
|
||||
t.Fatalf("received '%v' but expected '%v'", received, testCases[x].Expected)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestInArray(t *testing.T) {
|
||||
t.Parallel()
|
||||
InArray(nil, nil)
|
||||
|
||||
Reference in New Issue
Block a user