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

Method GetBooleanDefault

sessions/session.go:462–485  ·  view source on GitHub ↗

GetBooleanDefault same as `Get` but returns its boolean representation, if key doesn't exist then it returns the "defaultValue".

(key string, defaultValue bool)

Source from the content-addressed store, hash-verified

460// GetBooleanDefault same as `Get` but returns its boolean representation,
461// if key doesn't exist then it returns the "defaultValue".
462func (s *Session) GetBooleanDefault(key string, defaultValue bool) bool {
463 /*
464 Note that here we can't do more than duplicate the GetBoolean's code, because of the "false".
465 */
466 v := s.Get(key)
467 if v == nil {
468 return defaultValue
469 }
470
471 // here we could check for "true", "false" and 0 for false and 1 for true
472 // but this may cause unexpected behavior from the developer if they expecting an error
473 // so we just check if bool, if yes then return that bool, otherwise return false and an error.
474 if vb, ok := v.(bool); ok {
475 return vb
476 }
477
478 if vstring, ok := v.(string); ok {
479 if b, err := strconv.ParseBool(vstring); err == nil {
480 return b
481 }
482 }
483
484 return defaultValue
485}
486
487// GetAll returns a copy of all session's values.
488func (s *Session) GetAll() map[string]interface{} {

Callers 1

Calls 1

GetMethod · 0.95

Tested by 1