GetInt returns the value retrieved by `Get`, cast to a int64 if possible. If key data type do not match, it will return an error. SYS-REQ-003, SYS-REQ-075, SYS-REQ-076, SYS-REQ-077, SYS-REQ-078
(data []byte, keys ...string)
| 1991 | // If key data type do not match, it will return an error. |
| 1992 | // SYS-REQ-003, SYS-REQ-075, SYS-REQ-076, SYS-REQ-077, SYS-REQ-078 |
| 1993 | func GetInt(data []byte, keys ...string) (val int64, err error) { |
| 1994 | v, t, _, e := Get(data, keys...) |
| 1995 | |
| 1996 | if e != nil { |
| 1997 | return 0, e |
| 1998 | } |
| 1999 | |
| 2000 | if t != Number { |
| 2001 | if t == Null { |
| 2002 | return 0, NullValueError |
| 2003 | } |
| 2004 | return 0, fmt.Errorf("Value is not a number: %s", string(v)) |
| 2005 | } |
| 2006 | |
| 2007 | return ParseInt(v) |
| 2008 | } |
| 2009 | |
| 2010 | // GetBoolean returns the value retrieved by `Get`, cast to a bool if possible. |
| 2011 | // The offset is the same as in `Get`. |