diff options
Diffstat (limited to 'internal/stats/stats.go')
| -rw-r--r-- | internal/stats/stats.go | 19 |
1 files changed, 2 insertions, 17 deletions
diff --git a/internal/stats/stats.go b/internal/stats/stats.go index 4b05617..939e1aa 100644 --- a/internal/stats/stats.go +++ b/internal/stats/stats.go @@ -13,6 +13,7 @@ import ( "os" "path/filepath" "strconv" + "strings" "sync/atomic" "time" ) @@ -264,7 +265,7 @@ func TakeSnapshot() (Snapshot, error) { // CacheDir resolves the cache directory for stats. func CacheDir() (string, error) { - if x := os.Getenv("XDG_CACHE_HOME"); stringsTrim(x) != "" { + if x := os.Getenv("XDG_CACHE_HOME"); strings.TrimSpace(x) != "" { return filepath.Join(x, "hexai"), nil } home, err := os.UserHomeDir() @@ -274,22 +275,6 @@ func CacheDir() (string, error) { return filepath.Join(home, ".local", "hexai", "cache"), nil } -// stringsTrim is a tiny helper to avoid importing strings everywhere here. -func stringsTrim(s string) string { - i := 0 - j := len(s) - for i < j && (s[i] == ' ' || s[i] == '\t' || s[i] == '\n' || s[i] == '\r') { - i++ - } - for j > i && (s[j-1] == ' ' || s[j-1] == '\t' || s[j-1] == '\n' || s[j-1] == '\r') { - j-- - } - if i == 0 && j == len(s) { - return s - } - return s[i:j] -} - // DebugString returns a compact single-line view of a snapshot (useful for logs). func (s Snapshot) DebugString() string { return "Σ reqs=" + strconv.FormatInt(s.Global.Reqs, 10) + " rpm=" + fmt.Sprintf("%.2f", s.RPM) |
