Add support for HTML to String
This commit is contained in:
parent
312ed27bce
commit
0a58809502
@ -9,6 +9,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
"html/template"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestToInt(t *testing.T) {
|
func TestToInt(t *testing.T) {
|
||||||
@ -34,6 +35,7 @@ func TestToString(t *testing.T) {
|
|||||||
assert.Equal(t, ToString(8), "8")
|
assert.Equal(t, ToString(8), "8")
|
||||||
assert.Equal(t, ToString(8.12), "8.12")
|
assert.Equal(t, ToString(8.12), "8.12")
|
||||||
assert.Equal(t, ToString([]byte("one time")), "one time")
|
assert.Equal(t, ToString([]byte("one time")), "one time")
|
||||||
|
assert.Equal(t, ToString(template.HTML("one time")), "one time")
|
||||||
assert.Equal(t, ToString(foo), "one more time")
|
assert.Equal(t, ToString(foo), "one more time")
|
||||||
assert.Equal(t, ToString(nil), "")
|
assert.Equal(t, ToString(nil), "")
|
||||||
}
|
}
|
||||||
|
3
caste.go
3
caste.go
@ -8,6 +8,7 @@ package cast
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"html/template"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
@ -130,6 +131,8 @@ func ToStringE(i interface{}) (string, error) {
|
|||||||
return strconv.FormatInt(int64(i.(int)), 10), nil
|
return strconv.FormatInt(int64(i.(int)), 10), nil
|
||||||
case []byte:
|
case []byte:
|
||||||
return string(s), nil
|
return string(s), nil
|
||||||
|
case template.HTML:
|
||||||
|
return string(s), nil
|
||||||
case nil:
|
case nil:
|
||||||
return "", nil
|
return "", nil
|
||||||
default:
|
default:
|
||||||
|
Loading…
Reference in New Issue
Block a user