From 61d94a3ae0f43c4bf70dec41138b9af3ed70582c Mon Sep 17 00:00:00 2001 From: Matt Keller Date: Thu, 28 Jan 2016 13:33:21 -0500 Subject: [PATCH] Adds ability to cast int64's to strings Resolves #18 --- cast_test.go | 1 + caste.go | 2 ++ 2 files changed, 3 insertions(+) diff --git a/cast_test.go b/cast_test.go index e08887b..debef3d 100644 --- a/cast_test.go +++ b/cast_test.go @@ -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") diff --git a/caste.go b/caste.go index 3ac4cb7..e0a0004 100644 --- a/caste.go +++ b/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: