Type switch on otto.Value
Ugh, this is not documented in otto. Leaving a panic for future cases where dynamic typing will jump out at us. Fixes issue #160.
This commit is contained in:
parent
6308affc69
commit
5484d7eb35
1 changed files with 11 additions and 3 deletions
|
|
@ -191,10 +191,18 @@ func (s *Session) ToText(result interface{}) string {
|
||||||
} else {
|
} else {
|
||||||
if data.val.IsObject() {
|
if data.val.IsObject() {
|
||||||
export, _ := data.val.Export()
|
export, _ := data.val.Export()
|
||||||
mapExport := export.(map[string]string)
|
switch export := export.(type) {
|
||||||
for k, v := range mapExport {
|
case map[string]string:
|
||||||
|
for k, v := range export {
|
||||||
|
out += fmt.Sprintf("%s : %s\n", k, v)
|
||||||
|
}
|
||||||
|
case map[string]interface{}:
|
||||||
|
for k, v := range export {
|
||||||
out += fmt.Sprintf("%s : %v\n", k, v)
|
out += fmt.Sprintf("%s : %v\n", k, v)
|
||||||
}
|
}
|
||||||
|
default:
|
||||||
|
panic(fmt.Sprintf("unexpected type: %T", export))
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
strVersion, _ := data.val.ToString()
|
strVersion, _ := data.val.ToString()
|
||||||
out += fmt.Sprintf("%s\n", strVersion)
|
out += fmt.Sprintf("%s\n", strVersion)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue