parent
ee7b3e0353
commit
7c7add0129
@ -34,6 +34,7 @@ func TestToFloat64(t *testing.T) {
|
||||
func TestToString(t *testing.T) {
|
||||
var foo interface{} = "one more time"
|
||||
assert.Equal(t, ToString(8), "8")
|
||||
assert.Equal(t, ToString(int64(16)), "16")
|
||||
assert.Equal(t, ToString(8.12), "8.12")
|
||||
assert.Equal(t, ToString([]byte("one time")), "one time")
|
||||
assert.Equal(t, ToString(template.HTML("one time")), "one time")
|
||||
|
2
caste.go
2
caste.go
@ -198,6 +198,8 @@ func ToStringE(i interface{}) (string, error) {
|
||||
return strconv.FormatBool(s), nil
|
||||
case float64:
|
||||
return strconv.FormatFloat(i.(float64), 'f', -1, 64), nil
|
||||
case int64:
|
||||
return strconv.FormatInt(i.(int64), 10), nil
|
||||
case int:
|
||||
return strconv.FormatInt(int64(i.(int)), 10), nil
|
||||
case []byte:
|
||||
|
Loading…
Reference in New Issue
Block a user