GetString allows returning the attribute with the given key as a string. If the attribute JSON/YAML content is not a JSON string (or a primitive type that can be converted into a string), then the result will be the empty string and an error will be raised. An optional error holder can be passed as
(key string, errorHolder *error)
| 88 | // to receive any error that might have be raised during the attribute |
| 89 | // decoding |
| 90 | func (attributes Attributes) GetString(key string, errorHolder *error) string { |
| 91 | return attributes.getPrimitive( |
| 92 | key, |
| 93 | "", |
| 94 | "string", |
| 95 | func(attributes Attributes, key string, attributeType string) (interface{}, error) { |
| 96 | var convertedValue interface{} |
| 97 | var retryError error |
| 98 | switch attributeType { |
| 99 | case "bool": |
| 100 | convertedValue = strconv.FormatBool(attributes.GetBoolean(key, &retryError)) |
| 101 | case "number": |
| 102 | convertedValue = strconv.FormatFloat(attributes.GetNumber(key, &retryError), 'g', -1, 64) |
| 103 | } |
| 104 | return convertedValue, retryError |
| 105 | }, |
| 106 | errorHolder).(string) |
| 107 | } |
| 108 | |
| 109 | // GetNumber allows returning the attribute with the given key |
| 110 | // as a float64. If the attribute JSON/YAML content is |
no test coverage detected