Reduce nesting in sanity check
This commit is contained in:
parent
8913d71ca4
commit
e6ffeb4907
|
@ -86,15 +86,14 @@ func getLoad() (loads []float64, err error) {
|
||||||
func parseLoad(data string) (loads []float64, err error) {
|
func parseLoad(data string) (loads []float64, err error) {
|
||||||
loads = make([]float64, 3)
|
loads = make([]float64, 3)
|
||||||
parts := strings.Fields(data)
|
parts := strings.Fields(data)
|
||||||
if len(parts) >= 3 {
|
if len(parts) < 3 {
|
||||||
for i, load := range parts[0:3] {
|
|
||||||
loads[i], err = strconv.ParseFloat(load, 64)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("could not parse load '%s': %s", load, err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return nil, fmt.Errorf("unexpected content in %s", procFilePath("loadavg"))
|
return nil, fmt.Errorf("unexpected content in %s", procFilePath("loadavg"))
|
||||||
}
|
}
|
||||||
|
for i, load := range parts[0:3] {
|
||||||
|
loads[i], err = strconv.ParseFloat(load, 64)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("could not parse load '%s': %s", load, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
return loads, nil
|
return loads, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue