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

Method Get

pkg/attributes/attributes.go:193–207  ·  view source on GitHub ↗

Get allows returning the attribute with the given key as an interface. The underlying type of the returned interface depends on the JSON/YAML content of the attribute. It can be either a simple type like a string, a float64 or a bool, either a structured type like a map of interfaces or an array of

(key string, errorHolder *error)

Source from the content-addressed store, hash-verified

191// to receive any error that might have occurred during the attribute
192// decoding
193func (attributes Attributes) Get(key string, errorHolder *error) interface{} {
194 if attribute, exists := attributes[key]; exists {
195 container := &[]interface{}{}
196 err := json.Unmarshal([]byte("[ "+string(attribute.Raw)+" ]"), container)
197 if err != nil && errorHolder != nil {
198 *errorHolder = err
199 }
200 if len(*container) > 0 {
201 return (*container)[0]
202 }
203 } else if !exists && errorHolder != nil {
204 *errorHolder = &KeyNotFoundError{Key: key}
205 }
206 return nil
207}
208
209// GetInto allows decoding the attribute with the given key
210// into a given interface. The provided interface should be a pointer

Callers 15

TestDecodeAttributeFunction · 0.95
StringsMethod · 0.95
NumbersMethod · 0.95
BooleansMethod · 0.95
GenerateMethod · 0.80
ContainsPatchStrategyFunction · 0.80
GetPatchMergeKeyFunction · 0.80
GenerateMethod · 0.80
processMethod · 0.80
createOverrideMethod · 0.80
GenerateMethod · 0.80
GenerateMethod · 0.80

Calls

no outgoing calls

Tested by 2

TestDecodeAttributeFunction · 0.76
TestDecodeAttributeFunction · 0.64