Reflect actual slice type in TreeFromMap (#145)

* Reflect actual slice type in TreeFromMap
* Fix writeTo for slices tomlValues

Fixes #143
This commit is contained in:
Thomas Pelletier
2017-03-23 11:20:46 +01:00
committed by GitHub
parent 25e50242f6
commit f6e7596e8d
4 changed files with 36 additions and 20 deletions
+3
View File
@@ -65,6 +65,9 @@ func sliceToTree(object interface{}) (interface{}, error) {
value := reflect.ValueOf(object)
insideType := value.Type().Elem()
length := value.Len()
if length > 0 {
insideType = reflect.ValueOf(value.Index(0).Interface()).Type()
}
if insideType.Kind() == reflect.Map {
// this is considered as an array of tables
tablesArray := make([]*TomlTree, 0, length)