ObjectToMap function that returns the attributes for an object as a map. Keys are attribute names and values are the attribute's value. Two special keys _id and _type are also included in the map with object's identifier and type respectively. The map is filtered according to the filters specified i
(obj *vt.Object)
| 91 | // and type respectively. The map is filtered according to the filters specified |
| 92 | // in the --include and --exclude command-line arguments. |
| 93 | func ObjectToMap(obj *vt.Object) map[string]interface{} { |
| 94 | m := make(map[string]interface{}) |
| 95 | m["_id"] = obj.ID() |
| 96 | m["_type"] = obj.Type() |
| 97 | |
| 98 | contextAttributes := make(map[string]interface{}) |
| 99 | for _, attr := range obj.ContextAttributes() { |
| 100 | contextAttributes[attr], _ = obj.GetContext(attr) |
| 101 | } |
| 102 | if len(contextAttributes) > 0 { |
| 103 | m["_context_attributes"] = contextAttributes |
| 104 | } |
| 105 | |
| 106 | for _, attr := range obj.Attributes() { |
| 107 | m[attr], _ = obj.Get(attr) |
| 108 | } |
| 109 | for _, name := range obj.Relationships() { |
| 110 | r, _ := obj.GetRelationship(name) |
| 111 | relatedObjs := r.Objects() |
| 112 | if r.IsOneToOne() { |
| 113 | if len(relatedObjs) > 0 { |
| 114 | m[name] = relatedObjs[0].ID() |
| 115 | } else { |
| 116 | m[name] = nil |
| 117 | } |
| 118 | } else { |
| 119 | l := make([]string, 0) |
| 120 | for _, obj := range relatedObjs { |
| 121 | l = append(l, obj.ID()) |
| 122 | } |
| 123 | m[name] = l |
| 124 | } |
| 125 | } |
| 126 | return m |
| 127 | } |
| 128 | |
| 129 | // PrintObjects prints all the specified objects to stdout. |
| 130 | func (p *Printer) PrintObjects(objs []*vt.Object) error { |
no outgoing calls
no test coverage detected