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

Method GetBoolean

sessions/session.go:441–458  ·  view source on GitHub ↗

GetBoolean same as `Get` but returns its boolean representation, if key doesn't exist then it returns false and a non-nil error.

(key string)

Source from the content-addressed store, hash-verified

439// GetBoolean same as `Get` but returns its boolean representation,
440// if key doesn't exist then it returns false and a non-nil error.
441func (s *Session) GetBoolean(key string) (bool, error) {
442 v := s.Get(key)
443 if v == nil {
444 return false, newErrEntryNotFound(key, reflect.Bool, nil)
445 }
446
447 // here we could check for "true", "false" and 0 for false and 1 for true
448 // but this may cause unexpected behavior from the developer if they expecting an error
449 // so we just check if bool, if yes then return that bool, otherwise return false and an error.
450 if vb, ok := v.(bool); ok {
451 return vb, nil
452 }
453 if vstring, ok := v.(string); ok {
454 return strconv.ParseBool(vstring)
455 }
456
457 return false, newErrEntryNotFound(key, reflect.Bool, v)
458}
459
460// GetBooleanDefault same as `Get` but returns its boolean representation,
461// if key doesn't exist then it returns the "defaultValue".

Callers 1

secretFunction · 0.80

Calls 2

GetMethod · 0.95
newErrEntryNotFoundFunction · 0.85

Tested by

no test coverage detected