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)
| 97 | // to receive any error that might have be raised during the attribute |
| 98 | // decoding |
| 99 | func (attributes Attributes) GetString(key string, errorHolder *error) string { |
| 100 | return attributes.getPrimitive( |
| 101 | key, |
| 102 | "", |
| 103 | "string", |
| 104 | func(attributes Attributes, key string, attributeType string) (interface{}, error) { |
| 105 | var convertedValue interface{} |
| 106 | var retryError error |
| 107 | switch attributeType { |
| 108 | case "bool": |
| 109 | convertedValue = strconv.FormatBool(attributes.GetBoolean(key, &retryError)) |
| 110 | case "number": |
| 111 | convertedValue = strconv.FormatFloat(attributes.GetNumber(key, &retryError), 'g', -1, 64) |
| 112 | } |
| 113 | return convertedValue, retryError |
| 114 | }, |
| 115 | errorHolder).(string) |
| 116 | } |
| 117 | |
| 118 | // GetNumber allows returning the attribute with the given key |
| 119 | // as a float64. If the attribute JSON/YAML content is |