3
0

Allow Reader to cast to String

This commit is contained in:
Tomaž Jerman
2021-04-02 14:37:31 +02:00
parent 1f6a83280b
commit 7c759ceef8
+11 -1
View File
@@ -6,6 +6,7 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
"reflect"
@@ -288,7 +289,16 @@ func CastToBoolean(val interface{}) (out bool, err error) {
}
func CastToString(val interface{}) (out string, err error) {
return cast.ToStringE(UntypedValue(val))
switch v := val.(type) {
case io.Reader:
bb, err := ioutil.ReadAll(v)
if err != nil {
return "", err
}
return string(bb), nil
default:
return cast.ToStringE(UntypedValue(val))
}
}
func CastStringSlice(val interface{}) (out []string, err error) {