Skip to content

Commit

Permalink
fix float formatting
Browse files Browse the repository at this point in the history
fix float formatting
  • Loading branch information
NGRsoftlab authored Mar 27, 2023
1 parent c8da12d commit 3efe07b
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions cef_formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,43 @@ func MakeCefString(header CefHeader, contentMap map[string]interface{}, keysAreL
stringMap := make(map[string]string)

for key, value := range contentMap {
valueToSend := ""

switch value.(type) {
case float32:
if value == float32(int32(value.(float32))) {
valueToSend = fmt.Sprintf("%d", int32(value.(float32)))
} else {
valueToSend = fmt.Sprintf("%f", value)
}
case float64:
if value == float64(int64(value.(float64))) {
valueToSend = fmt.Sprintf("%d", int64(value.(float64)))
} else {
valueToSend = fmt.Sprintf("%f", value)
}
default:
valueToSend = fmt.Sprintf("%v", value)
}

// get real name from cef maps
if !useDefault {
okKey := CheckKey(key)

if !okKey {
// if we need some additional fields
if useCustom {
stringMap[key] = fmt.Sprintf("%v", value)
stringMap[key] = valueToSend
}
} else {
if keysAreLong {
stringMap[GetShortNameByLong(key)] = fmt.Sprintf("%v", value)
stringMap[GetShortNameByLong(key)] = valueToSend
} else {
stringMap[GetLongNameByShort(key)] = fmt.Sprintf("%v", value)
stringMap[GetLongNameByShort(key)] = valueToSend
}
}
} else {
stringMap[key] = fmt.Sprintf("%v", value)
stringMap[key] = valueToSend
}
}

Expand Down

0 comments on commit 3efe07b

Please sign in to comment.