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:
kortschak 2014-09-23 08:56:14 +09:30
parent 6308affc69
commit 5484d7eb35

View file

@ -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()