MCPcopy Create free account
hub / github.com/devfile/api / GetString

Method GetString

pkg/attributes/attributes.go:99–116  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

97// to receive any error that might have be raised during the attribute
98// decoding
99func (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

Callers 6

TestDecodeAttributeFunction · 0.95
GetNumberMethod · 0.95
GetBooleanMethod · 0.95
TestDecodeAttributeFunction · 0.80

Calls 3

getPrimitiveMethod · 0.95
GetBooleanMethod · 0.95
GetNumberMethod · 0.95

Tested by 2

TestDecodeAttributeFunction · 0.76
TestDecodeAttributeFunction · 0.64