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,9 +191,17 @@ func (s *Session) ToText(result interface{}) string {
|
|||
} else {
|
||||
if data.val.IsObject() {
|
||||
export, _ := data.val.Export()
|
||||
mapExport := export.(map[string]string)
|
||||
for k, v := range mapExport {
|
||||
out += fmt.Sprintf("%s : %v\n", k, v)
|
||||
switch export := export.(type) {
|
||||
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)
|
||||
}
|
||||
default:
|
||||
panic(fmt.Sprintf("unexpected type: %T", export))
|
||||
}
|
||||
} else {
|
||||
strVersion, _ := data.val.ToString()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue