MCPcopy Create free account
hub / github.com/kataras/iris / GetFloat32

Method GetFloat32

sessions/session.go:361–389  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
361func (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".

Callers 1

GetFloat32DefaultMethod · 0.95

Calls 2

GetMethod · 0.95
newErrEntryNotFoundFunction · 0.85

Tested by

no test coverage detected