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)
| 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. |
| 441 | func (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". |
no test coverage detected