GetNumber allows returning the attribute with the given key as a float64. If the attribute JSON/YAML content is not a JSON number (or a JSON string that can be converted into a JSON number), then the result will be the zero value and an error is raised. An optional error holder can be passed as an
(key string, errorHolder *error)
| 124 | // to receive any error that might have be raised during the attribute |
| 125 | // decoding |
| 126 | func (attributes Attributes) GetNumber(key string, errorHolder *error) float64 { |
| 127 | return attributes.getPrimitive( |
| 128 | key, |
| 129 | 0.0, |
| 130 | "number", |
| 131 | func(attributes Attributes, key string, attributeType string) (interface{}, error) { |
| 132 | var convertedValue interface{} |
| 133 | var retryError error |
| 134 | switch attributeType { |
| 135 | case "string": |
| 136 | var convError error |
| 137 | convertedValue, convError = strconv.ParseFloat(attributes.GetString(key, &retryError), 64) |
| 138 | if retryError == nil { |
| 139 | retryError = convError |
| 140 | } |
| 141 | } |
| 142 | return convertedValue, retryError |
| 143 | }, |
| 144 | errorHolder).(float64) |
| 145 | } |
| 146 | |
| 147 | // GetBoolean allows returning the attribute with the given key |
| 148 | // as a bool. If the attribute JSON/YAML content is |