Initial cloud-services repo - gateway service + pkg modules
This commit is contained in:
49
pkg/dbc/state/helpers.go
Normal file
49
pkg/dbc/state/helpers.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package state
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"time"
|
||||
)
|
||||
|
||||
const redisObjectExpire = 604800
|
||||
const errInvalidValue = "invalid value %f"
|
||||
|
||||
func FloatToBool(input float64) interface{} {
|
||||
return int(input) != 0
|
||||
}
|
||||
|
||||
func RoundMilli(input float64) interface{} {
|
||||
return math.Round(input*1000) / 1000
|
||||
}
|
||||
|
||||
func RoundGPS(input float64) interface{} {
|
||||
return math.Round(input*100000) / 100000
|
||||
}
|
||||
|
||||
func IntCeil(input float64) interface{} {
|
||||
return int(math.Ceil(input))
|
||||
}
|
||||
|
||||
func IntFloor(input float64) interface{} {
|
||||
return int(math.Floor(input))
|
||||
}
|
||||
|
||||
func Int(input float64) interface{} {
|
||||
return int(input)
|
||||
}
|
||||
|
||||
// WHy does this return an array of bytes instead of a string, or a time.Time
|
||||
func SerializeTimestampUSec(timestampUSec int) ([]byte, error) {
|
||||
return time.UnixMicro(int64(timestampUSec)).UTC().MarshalJSON()
|
||||
}
|
||||
|
||||
func GetMappedStrValues(valueMap map[float64]string) func(float64) interface{} {
|
||||
return func(input float64) interface{} {
|
||||
if value, ok := valueMap[input]; ok {
|
||||
return value
|
||||
}
|
||||
|
||||
return fmt.Sprintf(errInvalidValue, input)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user