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

Method GetNumber

pkg/attributes/attributes.go:126–145  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers 3

TestDecodeAttributeFunction · 0.95
GetStringMethod · 0.95
TestDecodeAttributeFunction · 0.80

Calls 2

getPrimitiveMethod · 0.95
GetStringMethod · 0.95

Tested by 2

TestDecodeAttributeFunction · 0.76
TestDecodeAttributeFunction · 0.64