ax(mining): replace banned strings import with unicode in miner_factory.go
Remove the banned "strings" import from miner_factory.go. Replace all strings.ToLower calls with a package-level toLowerASCII helper that uses unicode.ToLower per rune, matching the pattern used in other files. Co-Authored-By: Charon <charon@lethean.io>
This commit is contained in:
parent
c9e39451f0
commit
b6a2fb626e
1 changed files with 15 additions and 5 deletions
|
|
@ -1,10 +1,20 @@
|
|||
package mining
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"sync"
|
||||
"unicode"
|
||||
)
|
||||
|
||||
// toLowerASCII("XMRig") == "xmrig"
|
||||
// toLowerASCII("TT-Miner") == "tt-miner"
|
||||
func toLowerASCII(s string) string {
|
||||
runes := []rune(s)
|
||||
for i, r := range runes {
|
||||
runes[i] = unicode.ToLower(r)
|
||||
}
|
||||
return string(runes)
|
||||
}
|
||||
|
||||
// f.Register("custom", func() Miner { return NewCustomMiner() })
|
||||
type MinerConstructor func() Miner
|
||||
|
||||
|
|
@ -55,14 +65,14 @@ func (factory *MinerFactory) registerDefaults() {
|
|||
func (factory *MinerFactory) Register(name string, constructor MinerConstructor) {
|
||||
factory.mutex.Lock()
|
||||
defer factory.mutex.Unlock()
|
||||
factory.constructors[strings.ToLower(name)] = constructor
|
||||
factory.constructors[toLowerASCII(name)] = constructor
|
||||
}
|
||||
|
||||
// factory.RegisterAlias("ttminer", "tt-miner")
|
||||
func (factory *MinerFactory) RegisterAlias(alias, canonicalName string) {
|
||||
factory.mutex.Lock()
|
||||
defer factory.mutex.Unlock()
|
||||
factory.aliases[strings.ToLower(alias)] = strings.ToLower(canonicalName)
|
||||
factory.aliases[toLowerASCII(alias)] = toLowerASCII(canonicalName)
|
||||
}
|
||||
|
||||
// miner, err := factory.Create("xmrig")
|
||||
|
|
@ -70,7 +80,7 @@ func (factory *MinerFactory) Create(minerType string) (Miner, error) {
|
|||
factory.mutex.RLock()
|
||||
defer factory.mutex.RUnlock()
|
||||
|
||||
name := strings.ToLower(minerType)
|
||||
name := toLowerASCII(minerType)
|
||||
|
||||
// Check for alias first
|
||||
if canonical, ok := factory.aliases[name]; ok {
|
||||
|
|
@ -90,7 +100,7 @@ func (factory *MinerFactory) IsSupported(minerType string) bool {
|
|||
factory.mutex.RLock()
|
||||
defer factory.mutex.RUnlock()
|
||||
|
||||
name := strings.ToLower(minerType)
|
||||
name := toLowerASCII(minerType)
|
||||
|
||||
// Check alias
|
||||
if canonical, ok := factory.aliases[name]; ok {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue