GetFloat32 same as `Get` but returns its float32 representation, if key doesn't exist then it returns -1 and a non-nil error.
(key string)
| 359 | // GetFloat32 same as `Get` but returns its float32 representation, |
| 360 | // if key doesn't exist then it returns -1 and a non-nil error. |
| 361 | func (s *Session) GetFloat32(key string) (float32, error) { |
| 362 | v := s.Get(key) |
| 363 | |
| 364 | if vfloat32, ok := v.(float32); ok { |
| 365 | return vfloat32, nil |
| 366 | } |
| 367 | |
| 368 | if vfloat64, ok := v.(float64); ok { |
| 369 | return float32(vfloat64), nil |
| 370 | } |
| 371 | |
| 372 | if vint, ok := v.(int); ok { |
| 373 | return float32(vint), nil |
| 374 | } |
| 375 | |
| 376 | if vint64, ok := v.(int64); ok { |
| 377 | return float32(vint64), nil |
| 378 | } |
| 379 | |
| 380 | if vstring, sok := v.(string); sok { |
| 381 | vfloat64, err := strconv.ParseFloat(vstring, 32) |
| 382 | if err != nil { |
| 383 | return -1, err |
| 384 | } |
| 385 | return float32(vfloat64), nil |
| 386 | } |
| 387 | |
| 388 | return -1, newErrEntryNotFound(key, reflect.Float32, v) |
| 389 | } |
| 390 | |
| 391 | // GetFloat32Default same as `Get` but returns its float32 representation, |
| 392 | // if key doesn't exist then it returns the "defaultValue". |
no test coverage detected