From f2f18df9dbc3cd8e06c06e623d61eaf41296bc1e Mon Sep 17 00:00:00 2001 From: Liam Xu Date: Fri, 22 Mar 2019 10:21:01 -0700 Subject: [PATCH] Use Swith to replace if else Use Swith to replace if else --- process/process_darwin.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/process/process_darwin.go b/process/process_darwin.go index ea1a042..9a2f2e9 100644 --- a/process/process_darwin.go +++ b/process/process_darwin.go @@ -389,9 +389,8 @@ func convertCPUTimes(s string) (ret float64, err error) { var _tmp string if strings.Contains(s, ":") { _t := strings.Split(s, ":") - if len(_t) > 3 { - return ret, err - } else if len(_t) == 3 { + switch len(_t) { + case 3: hour, err := strconv.Atoi(_t[0]) if err != nil { return ret, err @@ -404,15 +403,17 @@ func convertCPUTimes(s string) (ret float64, err error) { } t += mins * 60 * ClockTicks _tmp = _t[2] - } else if len(_t) == 2 { + case 2: mins, err := strconv.Atoi(_t[0]) if err != nil { return ret, err } t += mins * 60 * ClockTicks _tmp = _t[1] - } else { + case 1, 0: _tmp = s + default: + return ret, err } } else { _tmp = s