GetInt64 same as `Get` but returns its int64 representation, if key doesn't exist then it returns -1 and a non-nil error.
(key string)
| 284 | // GetInt64 same as `Get` but returns its int64 representation, |
| 285 | // if key doesn't exist then it returns -1 and a non-nil error. |
| 286 | func (s *Session) GetInt64(key string) (int64, error) { |
| 287 | v := s.Get(key) |
| 288 | if v != nil { |
| 289 | if vint64, ok := v.(int64); ok { |
| 290 | return vint64, nil |
| 291 | } |
| 292 | |
| 293 | if vfloat64, ok := v.(float64); ok { |
| 294 | return int64(vfloat64), nil |
| 295 | } |
| 296 | |
| 297 | if vint, ok := v.(int); ok { |
| 298 | return int64(vint), nil |
| 299 | } |
| 300 | |
| 301 | if vstring, sok := v.(string); sok { |
| 302 | return strconv.ParseInt(vstring, 10, 64) |
| 303 | } |
| 304 | } |
| 305 | |
| 306 | return -1, newErrEntryNotFound(key, reflect.Int64, v) |
| 307 | } |
| 308 | |
| 309 | // GetInt64Default same as `Get` but returns its int64 representation, |
| 310 | // if key doesn't exist it returns the "defaultValue". |