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)
| 191 | // to receive any error that might have occurred during the attribute |
| 192 | // decoding |
| 193 | func (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 |
no outgoing calls