utils: remove excessive type assertions

Assign type switch variable to get properly-typed value
inside case clauses.

Signed-off-by: Iskander Sharipov <quasilyte@gmail.com>
pull/100/head
Iskander (Alex) Sharipov 6 years ago committed by GitHub
parent 7c131f6714
commit 3978ee8254
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -16,31 +16,31 @@ import (
// ToString converts a value to string. // ToString converts a value to string.
func ToString(value interface{}) string { func ToString(value interface{}) string {
switch value.(type) { switch value := value.(type) {
case string: case string:
return value.(string) return value
case int8: case int8:
return strconv.FormatInt(int64(value.(int8)), 10) return strconv.FormatInt(int64(value), 10)
case int16: case int16:
return strconv.FormatInt(int64(value.(int16)), 10) return strconv.FormatInt(int64(value), 10)
case int32: case int32:
return strconv.FormatInt(int64(value.(int32)), 10) return strconv.FormatInt(int64(value), 10)
case int64: case int64:
return strconv.FormatInt(int64(value.(int64)), 10) return strconv.FormatInt(int64(value), 10)
case uint8: case uint8:
return strconv.FormatUint(uint64(value.(uint8)), 10) return strconv.FormatUint(uint64(value), 10)
case uint16: case uint16:
return strconv.FormatUint(uint64(value.(uint16)), 10) return strconv.FormatUint(uint64(value), 10)
case uint32: case uint32:
return strconv.FormatUint(uint64(value.(uint32)), 10) return strconv.FormatUint(uint64(value), 10)
case uint64: case uint64:
return strconv.FormatUint(uint64(value.(uint64)), 10) return strconv.FormatUint(uint64(value), 10)
case float32: case float32:
return strconv.FormatFloat(float64(value.(float32)), 'g', -1, 64) return strconv.FormatFloat(float64(value), 'g', -1, 64)
case float64: case float64:
return strconv.FormatFloat(float64(value.(float64)), 'g', -1, 64) return strconv.FormatFloat(float64(value), 'g', -1, 64)
case bool: case bool:
return strconv.FormatBool(value.(bool)) return strconv.FormatBool(value)
default: default:
return fmt.Sprintf("%+v", value) return fmt.Sprintf("%+v", value)
} }

Loading…
Cancel
Save