ax(mining): replace banned strings import with unicode in miner_factory.go
Some checks are pending
Security Scan / security (push) Waiting to run
Test / test (push) Waiting to run

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:
Claude 2026-04-02 16:10:02 +01:00
parent c9e39451f0
commit b6a2fb626e
No known key found for this signature in database
GPG key ID: AF404715446AEB41

View file

@ -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 {