GetBoolean returns the value retrieved by `Get`, cast to a bool if possible. The offset is the same as in `Get`. If key data type do not match, it will return error. SYS-REQ-005, SYS-REQ-079
(data []byte, keys ...string)
| 2052 | // If key data type do not match, it will return error. |
| 2053 | // SYS-REQ-005, SYS-REQ-079 |
| 2054 | func GetBoolean(data []byte, keys ...string) (val bool, err error) { |
| 2055 | v, t, _, e := Get(data, keys...) |
| 2056 | |
| 2057 | if e != nil { |
| 2058 | return false, e |
| 2059 | } |
| 2060 | |
| 2061 | if t != Boolean { |
| 2062 | if t == Null { |
| 2063 | return false, NullValueError |
| 2064 | } |
| 2065 | return false, fmt.Errorf("Value is not a boolean: %s", string(v)) |
| 2066 | } |
| 2067 | |
| 2068 | return ParseBoolean(v) |
| 2069 | } |
| 2070 | |
| 2071 | // ParseBoolean parses a Boolean ValueType into a Go bool (not particularly useful, but here for completeness) |
| 2072 | // SYS-REQ-012, SYS-REQ-036, SYS-REQ-057, SYS-REQ-066 |