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:
+9
-4
@@ -8,6 +8,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
// encodes a string to a TOML-compliant string value
|
||||
@@ -60,9 +61,14 @@ func tomlValueStringRepresentation(v interface{}) (string, error) {
|
||||
return value.Format(time.RFC3339), nil
|
||||
case nil:
|
||||
return "", nil
|
||||
case []interface{}:
|
||||
}
|
||||
|
||||
rv := reflect.ValueOf(v)
|
||||
|
||||
if rv.Kind() == reflect.Slice {
|
||||
values := []string{}
|
||||
for _, item := range value {
|
||||
for i := 0; i < rv.Len(); i++ {
|
||||
item := rv.Index(i).Interface()
|
||||
itemRepr, err := tomlValueStringRepresentation(item)
|
||||
if err != nil {
|
||||
return "", err
|
||||
@@ -70,9 +76,8 @@ func tomlValueStringRepresentation(v interface{}) (string, error) {
|
||||
values = append(values, itemRepr)
|
||||
}
|
||||
return "[" + strings.Join(values, ",") + "]", nil
|
||||
default:
|
||||
return "", fmt.Errorf("unsupported value type %T: %v", value, value)
|
||||
}
|
||||
return "", fmt.Errorf("unsupported value type %T: %v", v, v)
|
||||
}
|
||||
|
||||
func (t *TomlTree) writeTo(w io.Writer, indent, keyspace string, bytesCount int64) (int64, error) {
|
||||
|
||||
Reference in New Issue
Block a user