GetString same as Get but returns its string representation, if key doesn't exist then it returns an empty string.
(key string)
| 132 | // GetString same as Get but returns its string representation, |
| 133 | // if key doesn't exist then it returns an empty string. |
| 134 | func (s *Session) GetString(key string) string { |
| 135 | if value := s.Get(key); value != nil { |
| 136 | if v, ok := value.(string); ok { |
| 137 | return v |
| 138 | } |
| 139 | |
| 140 | if v, ok := value.(int); ok { |
| 141 | return strconv.Itoa(v) |
| 142 | } |
| 143 | |
| 144 | if v, ok := value.(int64); ok { |
| 145 | return strconv.FormatInt(v, 10) |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | return "" |
| 150 | } |
| 151 | |
| 152 | // GetStringDefault same as Get but returns its string representation, |
| 153 | // if key doesn't exist then it returns the "defaultValue". |