mirror of
https://github.com/tw93/Mole.git
synced 2026-02-04 14:26:46 +00:00
Go code formatting optimization
This commit is contained in:
@@ -286,7 +286,7 @@ func commandExists(name string) bool {
|
||||
return false
|
||||
}
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
if r := recover(); r != nil { //nolint:staticcheck
|
||||
// Treat LookPath panics as "missing".
|
||||
}
|
||||
}()
|
||||
|
||||
@@ -32,7 +32,7 @@ func collectCPU() (CPUStatus, error) {
|
||||
}
|
||||
|
||||
// Two-call pattern for more reliable CPU usage.
|
||||
cpu.Percent(0, true)
|
||||
warmUpCpu()
|
||||
time.Sleep(cpuSampleInterval)
|
||||
percents, err := cpu.Percent(0, true)
|
||||
var totalPercent float64
|
||||
@@ -255,3 +255,7 @@ func fallbackCPUUtilization(logical int) (float64, []float64, error) {
|
||||
}
|
||||
return avg, perCore, nil
|
||||
}
|
||||
|
||||
func warmUpCpu() {
|
||||
cpu.Percent(0, true) //nolint:errcheck
|
||||
}
|
||||
|
||||
@@ -130,6 +130,8 @@ func parseInt(s string) int {
|
||||
return 0
|
||||
}
|
||||
var num int
|
||||
fmt.Sscanf(cleaned, "%d", &num)
|
||||
if _, err := fmt.Sscanf(cleaned, "%d", &num); err != nil {
|
||||
return 0
|
||||
}
|
||||
return num
|
||||
}
|
||||
|
||||
@@ -70,10 +70,12 @@ func calculateHealthScore(cpu CPUStatus, mem MemoryStatus, disks []DiskStatus, d
|
||||
}
|
||||
|
||||
// Memory pressure penalty.
|
||||
if mem.Pressure == "warn" {
|
||||
// Memory pressure penalty.
|
||||
switch mem.Pressure {
|
||||
case "warn":
|
||||
score -= memPressureWarnPenalty
|
||||
issues = append(issues, "Memory Pressure")
|
||||
} else if mem.Pressure == "critical" {
|
||||
case "critical":
|
||||
score -= memPressureCritPenalty
|
||||
issues = append(issues, "Critical Memory")
|
||||
}
|
||||
@@ -131,7 +133,7 @@ func calculateHealthScore(cpu CPUStatus, mem MemoryStatus, disks []DiskStatus, d
|
||||
}
|
||||
|
||||
// Build message.
|
||||
msg := "Excellent"
|
||||
var msg string
|
||||
if score >= 90 {
|
||||
msg = "Excellent"
|
||||
} else if score >= 75 {
|
||||
|
||||
@@ -308,9 +308,10 @@ func renderMemoryCard(mem MemoryStatus) cardData {
|
||||
if mem.Pressure != "" {
|
||||
pressureStyle := okStyle
|
||||
pressureText := "Status " + mem.Pressure
|
||||
if mem.Pressure == "warn" {
|
||||
switch mem.Pressure {
|
||||
case "warn":
|
||||
pressureStyle = warnStyle
|
||||
} else if mem.Pressure == "critical" {
|
||||
case "critical":
|
||||
pressureStyle = dangerStyle
|
||||
}
|
||||
lines = append(lines, pressureStyle.Render(pressureText))
|
||||
|
||||
Reference in New Issue
Block a user