瀏覽代碼

Add bool case to ToStringE

tags/v1.0.0
Cyrill Schumacher Steve Francia 8 年之前
父節點
當前提交
ee7b3e0353
共有 2 個檔案被更改,包括 4 行新增0 行删除
  1. +2
    -0
      cast_test.go
  2. +2
    -0
      caste.go

+ 2
- 0
cast_test.go 查看文件

@@ -40,6 +40,8 @@ func TestToString(t *testing.T) {
assert.Equal(t, ToString(template.URL("http://somehost.foo")), "http://somehost.foo")
assert.Equal(t, ToString(foo), "one more time")
assert.Equal(t, ToString(nil), "")
assert.Equal(t, ToString(true), "true")
assert.Equal(t, ToString(false), "false")
}

type foo struct {


+ 2
- 0
caste.go 查看文件

@@ -194,6 +194,8 @@ func ToStringE(i interface{}) (string, error) {
switch s := i.(type) {
case string:
return s, nil
case bool:
return strconv.FormatBool(s), nil
case float64:
return strconv.FormatFloat(i.(float64), 'f', -1, 64), nil
case int:


Loading…
取消
儲存