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

Method GetBoolean

pkg/attributes/attributes.go:163–182  ·  view source on GitHub ↗

GetBoolean allows returning the attribute with the given key as a bool. If the attribute JSON/YAML content is not a JSON boolean (or a JSON string that can be converted into a JSON boolean), then the result will be the `false` zero value and an error is raised. String values can be converted to bo

(key string, errorHolder *error)

Source from the content-addressed store, hash-verified

161// to receive any error that might have be raised during the attribute
162// decoding
163func (attributes Attributes) GetBoolean(key string, errorHolder *error) bool {
164 return attributes.getPrimitive(
165 key,
166 false,
167 "boolean",
168 func(attributes Attributes, key string, attributeType string) (interface{}, error) {
169 var convertedValue interface{}
170 var retryError error
171 switch attributeType {
172 case "string":
173 var convError error
174 convertedValue, convError = strconv.ParseBool(attributes.GetString(key, &retryError))
175 if retryError == nil {
176 retryError = convError
177 }
178 }
179 return convertedValue, retryError
180 },
181 errorHolder).(bool)
182}
183
184// Get allows returning the attribute with the given key
185// as an interface. The underlying type of the returned interface

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