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)
| 115 | // to receive any error that might have be raised during the attribute |
| 116 | // decoding |
| 117 | func (attributes Attributes) GetNumber(key string, errorHolder *error) float64 { |
| 118 | return attributes.getPrimitive( |
| 119 | key, |
| 120 | 0.0, |
| 121 | "number", |
| 122 | func(attributes Attributes, key string, attributeType string) (interface{}, error) { |
| 123 | var convertedValue interface{} |
| 124 | var retryError error |
| 125 | switch attributeType { |
| 126 | case "string": |
| 127 | var convError error |
| 128 | convertedValue, convError = strconv.ParseFloat(attributes.GetString(key, &retryError), 64) |
| 129 | if retryError == nil { |
| 130 | retryError = convError |
| 131 | } |
| 132 | } |
| 133 | return convertedValue, retryError |
| 134 | }, |
| 135 | errorHolder).(float64) |
| 136 | } |
| 137 | |
| 138 | // GetBoolean allows returning the attribute with the given key |
| 139 | // as a bool. If the attribute JSON/YAML content is |
no test coverage detected