Use Swith to replace if else
Use Swith to replace if else
This commit is contained in:
parent
6eb4d73bde
commit
f2f18df9db
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue