1
0
mirror of https://github.com/kataras/iris.git synced 2026-01-08 12:31:58 +00:00

fix https://github.com/kataras/iris/issues/1020, redis database stores the int as float64, so make that type assertion on GetInt as well

Former-commit-id: d29abdfe3a39fa1e046acbc5d118421a153d9c04
This commit is contained in:
Gerasimos Maropoulos
2018-06-03 02:47:48 +03:00
parent b4856d542d
commit f83e125d7f
2 changed files with 38 additions and 0 deletions

View File

@@ -176,6 +176,14 @@ func (s *Session) GetInt(key string) (int, error) {
return vint, nil
}
if vfloat64, ok := v.(float64); ok {
return int(vfloat64), nil
}
if vint64, ok := v.(int64); ok {
return int(vint64), nil
}
if vstring, sok := v.(string); sok {
return strconv.Atoi(vstring)
}
@@ -221,6 +229,10 @@ func (s *Session) GetInt64(key string) (int64, error) {
return vint64, nil
}
if vfloat64, ok := v.(float64); ok {
return int64(vfloat64), nil
}
if vint, ok := v.(int); ok {
return int64(vint), nil
}
@@ -259,6 +271,10 @@ func (s *Session) GetFloat32(key string) (float32, error) {
return float32(vint), nil
}
if vint64, ok := v.(int64); ok {
return float32(vint64), nil
}
if vstring, sok := v.(string); sok {
vfloat64, err := strconv.ParseFloat(vstring, 32)
if err != nil {
@@ -297,6 +313,10 @@ func (s *Session) GetFloat64(key string) (float64, error) {
return float64(vint), nil
}
if vint64, ok := v.(int64); ok {
return float64(vint64), nil
}
if vstring, sok := v.(string); sok {
return strconv.ParseFloat(vstring, 32)
}