ToString interface to string
(value interface{}, args ...int)
| 133 | |
| 134 | // ToString interface to string |
| 135 | func ToString(value interface{}, args ...int) (s string) { |
| 136 | switch v := value.(type) { |
| 137 | case bool: |
| 138 | s = strconv.FormatBool(v) |
| 139 | case float32: |
| 140 | s = strconv.FormatFloat(float64(v), 'f', argInt(args).Get(0, -1), argInt(args).Get(1, 32)) |
| 141 | case float64: |
| 142 | s = strconv.FormatFloat(v, 'f', argInt(args).Get(0, -1), argInt(args).Get(1, 64)) |
| 143 | case int: |
| 144 | s = strconv.FormatInt(int64(v), argInt(args).Get(0, 10)) |
| 145 | case int8: |
| 146 | s = strconv.FormatInt(int64(v), argInt(args).Get(0, 10)) |
| 147 | case int16: |
| 148 | s = strconv.FormatInt(int64(v), argInt(args).Get(0, 10)) |
| 149 | case int32: |
| 150 | s = strconv.FormatInt(int64(v), argInt(args).Get(0, 10)) |
| 151 | case int64: |
| 152 | s = strconv.FormatInt(v, argInt(args).Get(0, 10)) |
| 153 | case uint: |
| 154 | s = strconv.FormatUint(uint64(v), argInt(args).Get(0, 10)) |
| 155 | case uint8: |
| 156 | s = strconv.FormatUint(uint64(v), argInt(args).Get(0, 10)) |
| 157 | case uint16: |
| 158 | s = strconv.FormatUint(uint64(v), argInt(args).Get(0, 10)) |
| 159 | case uint32: |
| 160 | s = strconv.FormatUint(uint64(v), argInt(args).Get(0, 10)) |
| 161 | case uint64: |
| 162 | s = strconv.FormatUint(v, argInt(args).Get(0, 10)) |
| 163 | case string: |
| 164 | s = v |
| 165 | case []byte: |
| 166 | s = string(v) |
| 167 | default: |
| 168 | s = fmt.Sprintf("%v", v) |
| 169 | } |
| 170 | return s |
| 171 | } |
| 172 | |
| 173 | // ToInt64 interface to int64 |
| 174 | func ToInt64(value interface{}) (d int64) { |
no test coverage detected
searching dependent graphs…