diff --git a/config/config_map.go b/config/config_map.go index 92486a7..dd4f435 100644 --- a/config/config_map.go +++ b/config/config_map.go @@ -22,6 +22,7 @@ import ( "fmt" "log" "os" + "reflect" "strconv" "strings" ) @@ -162,11 +163,28 @@ func flatten(prefix string, inputMap map[string]interface{}, outputMap map[strin case map[string]interface{}: flatten(key, child, outputMap) default: - outputMap[key] = fmt.Sprintf("%v", v) + outputMap[key] = formatValue(v) } } } +func formatValue(v interface{}) string { + switch val := v.(type) { + case int, int8, int16, int32, int64: + return fmt.Sprintf("%d", val) + case uint, uint8, uint16, uint32, uint64: + return fmt.Sprintf("%d", val) + case float32, float64: + return strconv.FormatFloat(reflect.ValueOf(val).Float(), 'f', -1, 64) + case bool: + return strconv.FormatBool(val) + case string: + return val + default: + return fmt.Sprintf("%v", val) + } +} + type configOperationFunc func(config map[string]interface{}, key string) bool func visit(config map[string]interface{}, index int, keys []string, f configOperationFunc) bool {