@@ -22,6 +22,7 @@ import (
2222 "fmt"
2323 "log"
2424 "os"
25+ "reflect"
2526 "strconv"
2627 "strings"
2728)
@@ -162,11 +163,28 @@ func flatten(prefix string, inputMap map[string]interface{}, outputMap map[strin
162163 case map [string ]interface {}:
163164 flatten (key , child , outputMap )
164165 default :
165- outputMap [key ] = fmt . Sprintf ( "%v" , v )
166+ outputMap [key ] = formatValue ( v )
166167 }
167168 }
168169}
169170
171+ func formatValue (v interface {}) string {
172+ switch val := v .(type ) {
173+ case int , int8 , int16 , int32 , int64 :
174+ return fmt .Sprintf ("%d" , val )
175+ case uint , uint8 , uint16 , uint32 , uint64 :
176+ return fmt .Sprintf ("%d" , val )
177+ case float32 , float64 :
178+ return strconv .FormatFloat (reflect .ValueOf (val ).Float (), 'f' , - 1 , 64 )
179+ case bool :
180+ return strconv .FormatBool (val )
181+ case string :
182+ return val
183+ default :
184+ return fmt .Sprintf ("%v" , val )
185+ }
186+ }
187+
170188type configOperationFunc func (config map [string ]interface {}, key string ) bool
171189
172190func visit (config map [string ]interface {}, index int , keys []string , f configOperationFunc ) bool {
0 commit comments