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