(collection, objectID, relationship string, limit int)
| 55 | } |
| 56 | |
| 57 | func getRelatedObjects(collection, objectID, relationship string, limit int) ([]map[string]interface{}, error) { |
| 58 | if collection == "urls" { |
| 59 | // If collections is "urls" the objectID is the URL itself and |
| 60 | // it needs to be encoded in base64. |
| 61 | objectID = base64.RawURLEncoding.EncodeToString([]byte(objectID)) |
| 62 | } |
| 63 | client, err := NewAPIClient() |
| 64 | if err != nil { |
| 65 | return nil, err |
| 66 | } |
| 67 | it, err := client.Iterator( |
| 68 | vt.URL("%s/%s/%s", collection, objectID, relationship), |
| 69 | vt.IteratorLimit(limit)) |
| 70 | if err != nil { |
| 71 | return nil, err |
| 72 | } |
| 73 | defer it.Close() |
| 74 | result := make([]map[string]interface{}, 0) |
| 75 | for it.Next() { |
| 76 | obj := it.Get() |
| 77 | result = append(result, utils.ObjectToMap(obj)) |
| 78 | } |
| 79 | if err := it.Error(); err != nil { |
| 80 | return nil, err |
| 81 | } |
| 82 | return result, nil |
| 83 | } |
| 84 | |
| 85 | // NewRelationshipCmd returns a new instance of the 'relationship' command. |
| 86 | func NewRelationshipCmd(collection, relationship, use, description string, private_flag bool) *cobra.Command { |
no test coverage detected