committed by
Thomas Pelletier
parent
fee7787d3f
commit
62e2d802ed
+7
-4
@@ -48,6 +48,8 @@ func simpleValueCoercion(object interface{}) (interface{}, error) {
|
||||
return uint64(original), nil
|
||||
case float32:
|
||||
return float64(original), nil
|
||||
case fmt.Stringer:
|
||||
return original.String(), nil
|
||||
default:
|
||||
return nil, fmt.Errorf("cannot convert type %T to TomlTree", object)
|
||||
}
|
||||
@@ -102,9 +104,10 @@ func toTree(object interface{}) (interface{}, error) {
|
||||
values := map[string]interface{}{}
|
||||
keys := value.MapKeys()
|
||||
for _, key := range keys {
|
||||
k, ok := key.Interface().(string)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("map key needs to be a string, not %T", key.Interface())
|
||||
if key.Kind() != reflect.String {
|
||||
if _, ok := key.Interface().(string); !ok {
|
||||
return nil, fmt.Errorf("map key needs to be a string, not %T (%v)", key.Interface(), key.Kind())
|
||||
}
|
||||
}
|
||||
|
||||
v := value.MapIndex(key)
|
||||
@@ -112,7 +115,7 @@ func toTree(object interface{}) (interface{}, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
values[k] = newValue
|
||||
values[key.String()] = newValue
|
||||
}
|
||||
return &TomlTree{values, Position{}}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user