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)
| 455 | // to receive any error that might have occured during the attributes |
| 456 | // decoding |
| 457 | func (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 | } |