| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
package utils |
| 11 |
|
| 12 |
import ( |
| 13 |
"fmt" |
| 14 |
"strconv" |
| 15 |
) |
| 16 |
|
| 17 |
|
| 18 |
func ToString(value interface{}) string { |
| 19 |
switch value := value.(type) { |
| 20 |
case string: |
| 21 |
return value |
| 22 |
case int8: |
| 23 |
return strconv.FormatInt(int64(value), 10) |
| 24 |
case int16: |
| 25 |
return strconv.FormatInt(int64(value), 10) |
| 26 |
case int32: |
| 27 |
return strconv.FormatInt(int64(value), 10) |
| 28 |
case int64: |
| 29 |
return strconv.FormatInt(value, 10) |
| 30 |
case uint8: |
| 31 |
return strconv.FormatUint(uint64(value), 10) |
| 32 |
case uint16: |
| 33 |
return strconv.FormatUint(uint64(value), 10) |
| 34 |
case uint32: |
| 35 |
return strconv.FormatUint(uint64(value), 10) |
| 36 |
case uint64: |
| 37 |
return strconv.FormatUint(value, 10) |
| 38 |
case float32: |
| 39 |
return strconv.FormatFloat(float64(value), 'g', -1, 64) |
| 40 |
case float64: |
| 41 |
return strconv.FormatFloat(value, 'g', -1, 64) |
| 42 |
case bool: |
| 43 |
return strconv.FormatBool(value) |
| 44 |
default: |
| 45 |
return fmt.Sprintf("%+v", value) |
| 46 |
} |
| 47 |
} |