GetInt same as `Get` but returns its int representation, if key doesn't exist then it returns -1 and a non-nil error.
(key string)
| 229 | // GetInt same as `Get` but returns its int representation, |
| 230 | // if key doesn't exist then it returns -1 and a non-nil error. |
| 231 | func (s *Session) GetInt(key string) (int, error) { |
| 232 | v := s.Get(key) |
| 233 | |
| 234 | if v != nil { |
| 235 | if vint, ok := v.(int); ok { |
| 236 | return vint, nil |
| 237 | } |
| 238 | |
| 239 | if vfloat64, ok := v.(float64); ok { |
| 240 | return int(vfloat64), nil |
| 241 | } |
| 242 | |
| 243 | if vint64, ok := v.(int64); ok { |
| 244 | return int(vint64), nil |
| 245 | } |
| 246 | |
| 247 | if vstring, sok := v.(string); sok { |
| 248 | return strconv.Atoi(vstring) |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | return -1, newErrEntryNotFound(key, reflect.Int, v) |
| 253 | } |
| 254 | |
| 255 | // GetIntDefault same as `Get` but returns its int representation, |
| 256 | // if key doesn't exist then it returns the "defaultValue". |
no test coverage detected