GetInt returns the int value with specified key stored in session object.
(key string)
| 47 | |
| 48 | // GetInt returns the int value with specified key stored in session object. |
| 49 | func (s *Session) GetInt(key string) (value int64, exists bool) { |
| 50 | rv, exists := s.Get(key) |
| 51 | if !exists { |
| 52 | return |
| 53 | } |
| 54 | |
| 55 | switch v := rv.(type) { |
| 56 | case int: |
| 57 | value = int64(v) |
| 58 | case int8: |
| 59 | value = int64(v) |
| 60 | case int16: |
| 61 | value = int64(v) |
| 62 | case int32: |
| 63 | value = int64(v) |
| 64 | case int64: |
| 65 | value = v |
| 66 | case uint: |
| 67 | value = int64(v) |
| 68 | case uint8: |
| 69 | value = int64(v) |
| 70 | case uint16: |
| 71 | value = int64(v) |
| 72 | case uint32: |
| 73 | value = int64(v) |
| 74 | case uint64: |
| 75 | value = int64(v) |
| 76 | case float32: |
| 77 | value = int64(v) |
| 78 | case float64: |
| 79 | value = int64(v) |
| 80 | case bool: |
| 81 | if v { |
| 82 | value = 1 |
| 83 | } else { |
| 84 | value = 0 |
| 85 | } |
| 86 | case string: |
| 87 | var err error |
| 88 | value, err = strconv.ParseInt(v, 10, 64) |
| 89 | if err != nil { |
| 90 | exists = false |
| 91 | } |
| 92 | return |
| 93 | default: |
| 94 | exists = false |
| 95 | } |
| 96 | |
| 97 | return |
| 98 | } |
| 99 | |
| 100 | // GetUint returns the unsigned int value with specified key stored in session object. |
| 101 | func (s *Session) GetUint(key string) (value uint64, exists bool) { |