Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion config/config_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"fmt"
"log"
"os"
"reflect"
"strconv"
"strings"
)
Expand Down Expand Up @@ -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 {
Expand Down
Loading