aboutsummaryrefslogtreecommitdiff
path: root/vendor/github.com/pelletier/go-toml/tomltree_conversions.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/pelletier/go-toml/tomltree_conversions.go')
-rw-r--r--vendor/github.com/pelletier/go-toml/tomltree_conversions.go54
1 files changed, 53 insertions, 1 deletions
diff --git a/vendor/github.com/pelletier/go-toml/tomltree_conversions.go b/vendor/github.com/pelletier/go-toml/tomltree_conversions.go
index c9c6f95..bf9321b 100644
--- a/vendor/github.com/pelletier/go-toml/tomltree_conversions.go
+++ b/vendor/github.com/pelletier/go-toml/tomltree_conversions.go
@@ -45,8 +45,28 @@ func encodeTomlString(value string) string {
func toTomlValue(item interface{}, indent int) string {
tab := strings.Repeat(" ", indent)
switch value := item.(type) {
+ case int:
+ return tab + strconv.FormatInt(int64(value), 10)
+ case int8:
+ return tab + strconv.FormatInt(int64(value), 10)
+ case int16:
+ return tab + strconv.FormatInt(int64(value), 10)
+ case int32:
+ return tab + strconv.FormatInt(int64(value), 10)
case int64:
return tab + strconv.FormatInt(value, 10)
+ case uint:
+ return tab + strconv.FormatUint(uint64(value), 10)
+ case uint8:
+ return tab + strconv.FormatUint(uint64(value), 10)
+ case uint16:
+ return tab + strconv.FormatUint(uint64(value), 10)
+ case uint32:
+ return tab + strconv.FormatUint(uint64(value), 10)
+ case uint64:
+ return tab + strconv.FormatUint(value, 10)
+ case float32:
+ return tab + strconv.FormatFloat(float64(value), 'f', -1, 32)
case float64:
return tab + strconv.FormatFloat(value, 'f', -1, 64)
case string:
@@ -64,8 +84,10 @@ func toTomlValue(item interface{}, indent int) string {
result += toTomlValue(item, indent+2) + ",\n"
}
return result + tab + "]"
+ case nil:
+ return ""
default:
- panic(fmt.Sprintf("unsupported value type: %v", value))
+ panic(fmt.Sprintf("unsupported value type %T: %v", value, value))
}
}
@@ -100,6 +122,20 @@ func (t *TomlTree) toToml(indent, keyspace string) string {
result += fmt.Sprintf("\n%s[%s]\n", indent, combinedKey)
}
result += sub.toToml(indent+" ", combinedKey)
+ case map[string]string:
+ sub := TreeFromMap(convertMapStringString(node))
+
+ if len(sub.Keys()) > 0 {
+ result += fmt.Sprintf("\n%s[%s]\n", indent, combinedKey)
+ }
+ result += sub.toToml(indent+" ", combinedKey)
+ case map[interface{}]interface{}:
+ sub := TreeFromMap(convertMapInterfaceInterface(node))
+
+ if len(sub.Keys()) > 0 {
+ result += fmt.Sprintf("\n%s[%s]\n", indent, combinedKey)
+ }
+ result += sub.toToml(indent+" ", combinedKey)
case *tomlValue:
result += fmt.Sprintf("%s%s = %s\n", indent, k, toTomlValue(node.value, 0))
default:
@@ -109,6 +145,22 @@ func (t *TomlTree) toToml(indent, keyspace string) string {
return result
}
+func convertMapStringString(in map[string]string) map[string]interface{} {
+ result := make(map[string]interface{}, len(in))
+ for k, v := range in {
+ result[k] = v
+ }
+ return result
+}
+
+func convertMapInterfaceInterface(in map[interface{}]interface{}) map[string]interface{} {
+ result := make(map[string]interface{}, len(in))
+ for k, v := range in {
+ result[k.(string)] = v
+ }
+ return result
+}
+
// ToString is an alias for String
func (t *TomlTree) ToString() string {
return t.String()