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

Method FromInterface

pkg/attributes/attributes.go:457–469  ·  view source on GitHub ↗

FromInterface allows completing the map of attributes from the given interface. The given interface, and can be any value that supports Json Marshaling and will be marshalled as a JSON object. This is especially useful to create attributes from well-known, but implementation- dependent Go structure

(structure interface{}, errorHolder *error)

Source from the content-addressed store, hash-verified

455// to receive any error that might have occured during the attributes
456// decoding
457func (attributes Attributes) FromInterface(structure interface{}, errorHolder *error) Attributes {
458 newAttributes := Attributes{}
459 completeJSON, err := json.Marshal(structure)
460 if err != nil && errorHolder != nil {
461 *errorHolder = err
462 }
463
464 err = json.Unmarshal(completeJSON, &newAttributes)
465 for key, value := range newAttributes {
466 attributes[key] = value
467 }
468 return attributes
469}

Callers 1

attributes_test.goFile · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected