From b12db106800c409663cb8a11a6e43da810bdf34b Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 2 Apr 2026 18:27:21 +0100 Subject: [PATCH] ax(batch): expand abbreviated parameter and local variable names across all packages Applies AX principle 1 (Predictable Names Over Short Names) to function signatures and local variables: s->input/raw, v->target/value, d->duration, a,b->left,right, w->writer, r->reader, l->logger, p->part/databasePoint, fn parameter names left as-is where they are callback conventions. Co-Authored-By: Charon --- pkg/database/hashrate.go | 10 +++++----- pkg/logging/logger.go | 10 +++++----- pkg/mining/auth.go | 4 ++-- pkg/mining/bufpool.go | 8 ++++---- pkg/mining/manager.go | 24 ++++++++++++------------ pkg/mining/metrics.go | 8 ++++---- pkg/mining/miner.go | 8 ++++---- pkg/mining/miner_factory.go | 4 ++-- pkg/mining/mining.go | 4 ++-- pkg/node/bufpool.go | 8 ++++---- pkg/node/bundle.go | 8 ++++---- 11 files changed, 48 insertions(+), 48 deletions(-) diff --git a/pkg/database/hashrate.go b/pkg/database/hashrate.go index be2904f..53fdc67 100644 --- a/pkg/database/hashrate.go +++ b/pkg/database/hashrate.go @@ -9,8 +9,8 @@ import ( // t := parseSQLiteTimestamp("2006-01-02 15:04:05") // time.Time{...} // t := parseSQLiteTimestamp("") // time.Time{} (zero) -func parseSQLiteTimestamp(s string) time.Time { - if s == "" { +func parseSQLiteTimestamp(raw string) time.Time { + if raw == "" { return time.Time{} } @@ -24,12 +24,12 @@ func parseSQLiteTimestamp(s string) time.Time { } for _, format := range formats { - if t, err := time.Parse(format, s); err == nil { - return t + if parsed, err := time.Parse(format, raw); err == nil { + return parsed } } - logging.Warn("failed to parse timestamp from database", logging.Fields{"timestamp": s}) + logging.Warn("failed to parse timestamp from database", logging.Fields{"timestamp": raw}) return time.Time{} } diff --git a/pkg/logging/logger.go b/pkg/logging/logger.go index 8996448..ffc95c8 100644 --- a/pkg/logging/logger.go +++ b/pkg/logging/logger.go @@ -209,10 +209,10 @@ var ( ) // logging.SetGlobal(logging.New(logging.Config{Level: logging.LevelDebug})) -func SetGlobal(l *Logger) { +func SetGlobal(logger *Logger) { globalMutex.Lock() defer globalMutex.Unlock() - globalLogger = l + globalLogger = logger } // logger := logging.GetGlobal() @@ -274,8 +274,8 @@ func Errorf(format string, args ...interface{}) { // level, err := logging.ParseLevel("DEBUG") // LevelDebug, nil // level, err := logging.ParseLevel("nope") // LevelInfo, error -func ParseLevel(s string) (Level, error) { - switch strings.ToUpper(s) { +func ParseLevel(input string) (Level, error) { + switch strings.ToUpper(input) { case "DEBUG": return LevelDebug, nil case "INFO": @@ -285,6 +285,6 @@ func ParseLevel(s string) (Level, error) { case "ERROR": return LevelError, nil default: - return LevelInfo, fmt.Errorf("unknown log level: %s", s) + return LevelInfo, fmt.Errorf("unknown log level: %s", input) } } diff --git a/pkg/mining/auth.go b/pkg/mining/auth.go index 8deac7e..8e00015 100644 --- a/pkg/mining/auth.go +++ b/pkg/mining/auth.go @@ -254,7 +254,7 @@ func parseDigestParams(header string) map[string]string { } // h := md5Hash("user:realm:pass") // "5f4dcc3b5aa765d61d8327deb882cf99" -func md5Hash(s string) string { - digest := md5.Sum([]byte(s)) +func md5Hash(input string) string { + digest := md5.Sum([]byte(input)) return hex.EncodeToString(digest[:]) } diff --git a/pkg/mining/bufpool.go b/pkg/mining/bufpool.go index 8d2034b..6c6c5f3 100644 --- a/pkg/mining/bufpool.go +++ b/pkg/mining/bufpool.go @@ -30,19 +30,19 @@ func putBuffer(buf *bytes.Buffer) { } // UnmarshalJSON(data, &msg) -func UnmarshalJSON(data []byte, v interface{}) error { - return json.Unmarshal(data, v) +func UnmarshalJSON(data []byte, target interface{}) error { + return json.Unmarshal(data, target) } // data, err := MarshalJSON(stats) // pooled buffer; safe to hold after call -func MarshalJSON(v interface{}) ([]byte, error) { +func MarshalJSON(value interface{}) ([]byte, error) { buf := getBuffer() defer putBuffer(buf) encoder := json.NewEncoder(buf) // Don't escape HTML characters (matches json.Marshal behavior for these use cases) encoder.SetEscapeHTML(false) - if err := encoder.Encode(v); err != nil { + if err := encoder.Encode(value); err != nil { return nil, err } diff --git a/pkg/mining/manager.go b/pkg/mining/manager.go index 47bb993..bb77f11 100644 --- a/pkg/mining/manager.go +++ b/pkg/mining/manager.go @@ -15,27 +15,27 @@ import ( // equalFold("xmrig", "XMRig") == true // equalFold("tt-miner", "TT-Miner") == true -func equalFold(a, b string) bool { - return bytes.EqualFold([]byte(a), []byte(b)) +func equalFold(left, right string) bool { + return bytes.EqualFold([]byte(left), []byte(right)) } // hasPrefix("xmrig-rx0", "xmrig") == true // hasPrefix("ttminer-rtx", "xmrig") == false -func hasPrefix(s, prefix string) bool { - return len(s) >= len(prefix) && s[:len(prefix)] == prefix +func hasPrefix(input, prefix string) bool { + return len(input) >= len(prefix) && input[:len(prefix)] == prefix } // containsStr("peer not found", "not found") == true // containsStr("connection ok", "not found") == false -func containsStr(s, substr string) bool { - if len(substr) == 0 { +func containsStr(haystack, needle string) bool { + if len(needle) == 0 { return true } - if len(s) < len(substr) { + if len(haystack) < len(needle) { return false } - for i := 0; i <= len(s)-len(substr); i++ { - if s[i:i+len(substr)] == substr { + for i := 0; i <= len(haystack)-len(needle); i++ { + if haystack[i:i+len(needle)] == needle { return true } } @@ -788,10 +788,10 @@ func (m *Manager) GetMinerHistoricalHashrate(minerName string, since, until time // Convert database points to mining points points := make([]HashratePoint, len(dbPoints)) - for i, p := range dbPoints { + for i, databasePoint := range dbPoints { points[i] = HashratePoint{ - Timestamp: p.Timestamp, - Hashrate: p.Hashrate, + Timestamp: databasePoint.Timestamp, + Hashrate: databasePoint.Hashrate, } } return points, nil diff --git a/pkg/mining/metrics.go b/pkg/mining/metrics.go index 2895b5f..83a3d43 100644 --- a/pkg/mining/metrics.go +++ b/pkg/mining/metrics.go @@ -51,7 +51,7 @@ func NewLatencyHistogram(maxSize int) *LatencyHistogram { } // h.Record(42 * time.Millisecond) // call after each request completes -func (histogram *LatencyHistogram) Record(d time.Duration) { +func (histogram *LatencyHistogram) Record(duration time.Duration) { histogram.mutex.Lock() defer histogram.mutex.Unlock() @@ -60,7 +60,7 @@ func (histogram *LatencyHistogram) Record(d time.Duration) { copy(histogram.samples, histogram.samples[1:]) histogram.samples = histogram.samples[:len(histogram.samples)-1] } - histogram.samples = append(histogram.samples, d) + histogram.samples = append(histogram.samples, duration) } // avg := h.Average() // returns 0 if no samples recorded @@ -73,8 +73,8 @@ func (histogram *LatencyHistogram) Average() time.Duration { } var total time.Duration - for _, d := range histogram.samples { - total += d + for _, sample := range histogram.samples { + total += sample } return total / time.Duration(len(histogram.samples)) } diff --git a/pkg/mining/miner.go b/pkg/mining/miner.go index 8edc8f7..2283e93 100644 --- a/pkg/mining/miner.go +++ b/pkg/mining/miner.go @@ -288,11 +288,11 @@ func (b *BaseMiner) InstallFromURL(url string) error { // a := parseVersion("6.24.0") // [6, 24, 0] // b := parseVersion("5.0.1") // [5, 0, 1] // if compareVersions(a, b) > 0 { /* a is newer */ } -func parseVersion(v string) []int { - parts := strings.Split(v, ".") +func parseVersion(versionString string) []int { + parts := strings.Split(versionString, ".") intParts := make([]int, len(parts)) - for i, p := range parts { - val, err := strconv.Atoi(p) + for i, part := range parts { + val, err := strconv.Atoi(part) if err != nil { return []int{0} // Malformed version, treat as very old } diff --git a/pkg/mining/miner_factory.go b/pkg/mining/miner_factory.go index 3acc06c..223ce9b 100644 --- a/pkg/mining/miner_factory.go +++ b/pkg/mining/miner_factory.go @@ -7,8 +7,8 @@ import ( // toLowerASCII("XMRig") == "xmrig" // toLowerASCII("TT-Miner") == "tt-miner" -func toLowerASCII(s string) string { - runes := []rune(s) +func toLowerASCII(input string) string { + runes := []rune(input) for i, r := range runes { runes[i] = unicode.ToLower(r) } diff --git a/pkg/mining/mining.go b/pkg/mining/mining.go index 130e10c..f1227d0 100644 --- a/pkg/mining/mining.go +++ b/pkg/mining/mining.go @@ -211,8 +211,8 @@ func (c *Config) Validate() error { // containsShellChars(";echo bad") == true // containsShellChars("stratum+tcp://pool.example.com:3333") == false -func containsShellChars(s string) bool { - for _, r := range s { +func containsShellChars(input string) bool { + for _, r := range input { switch r { case ';', '|', '&', '`', '$', '(', ')', '{', '}', '<', '>', '\n', '\r', '\\', '\'', '"', '!': return true diff --git a/pkg/node/bufpool.go b/pkg/node/bufpool.go index 7815449..36c580a 100644 --- a/pkg/node/bufpool.go +++ b/pkg/node/bufpool.go @@ -31,20 +31,20 @@ func putBuffer(buffer *bytes.Buffer) { // var msg Message // if err := UnmarshalJSON(data, &msg); err != nil { return nil, err } -func UnmarshalJSON(data []byte, v interface{}) error { - return json.Unmarshal(data, v) +func UnmarshalJSON(data []byte, target interface{}) error { + return json.Unmarshal(data, target) } // data, err := MarshalJSON(msg) // if err != nil { return nil, err } -func MarshalJSON(v interface{}) ([]byte, error) { +func MarshalJSON(value interface{}) ([]byte, error) { buffer := getBuffer() defer putBuffer(buffer) encoder := json.NewEncoder(buffer) // Don't escape HTML characters (matches json.Marshal behavior for these use cases) encoder.SetEscapeHTML(false) - if err := encoder.Encode(v); err != nil { + if err := encoder.Encode(value); err != nil { return nil, err } diff --git a/pkg/node/bundle.go b/pkg/node/bundle.go index 17866fd..cd4426d 100644 --- a/pkg/node/bundle.go +++ b/pkg/node/bundle.go @@ -352,16 +352,16 @@ func extractTarball(tarData []byte, destDir string) (string, error) { // StreamBundle(bundle, conn) // stream to peer over WebSocket or HTTP body // StreamBundle(bundle, os.Stdout) // debug: print bundle JSON to stdout -func StreamBundle(bundle *Bundle, w io.Writer) error { - encoder := json.NewEncoder(w) +func StreamBundle(bundle *Bundle, writer io.Writer) error { + encoder := json.NewEncoder(writer) return encoder.Encode(bundle) } // bundle, err := ReadBundle(conn) // read from WebSocket or HTTP response body // if err != nil { return nil, fmt.Errorf("read bundle: %w", err) } -func ReadBundle(r io.Reader) (*Bundle, error) { +func ReadBundle(reader io.Reader) (*Bundle, error) { var bundle Bundle - decoder := json.NewDecoder(r) + decoder := json.NewDecoder(reader) if err := decoder.Decode(&bundle); err != nil { return nil, err }