MCPcopy Create free account
hub / github.com/kataras/iris / GetInt

Method GetInt

sessions/session.go:231–253  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
231func (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".

Callers 1

GetIntDefaultMethod · 0.95

Calls 2

GetMethod · 0.95
newErrEntryNotFoundFunction · 0.85

Tested by

no test coverage detected