2 Copyright (C) The Arvados Authors. All rights reserved.
4 SPDX-License-Identifier: CC-BY-SA-3.0
10 // *******************
11 // Import the modules.
13 // Our examples don't use keepclient, but they do use fmt and log to
18 "git.curoverse.com/arvados.git/sdk/go/arvadosclient"
25 // ********************************
26 // Set up an API client user agent.
29 arv, err := arvadosclient.MakeArvadosClient()
31 log.Fatalf("Error setting up arvados client %s", err.Error())
35 // *****************************************
36 // Print the full name of the current user.
40 // Remember to start each field name with a capital letter,
41 // otherwise it won't get populated by the arvados client because
42 // the field will be invisible to it.
43 Uuid string `json:"uuid"`
44 FullName string `json:"full_name"`
48 err = arv.Call("GET", "users", "", "current", nil, &u)
51 log.Fatalf("error querying current user", err.Error())
54 log.Printf("Logged in as %s (uuid %s)", u.FullName, u.Uuid)
57 // ********************************************************
58 // Print all fields from the first five collections returned.
60 // Note that some fields, are not returned by default and have to be
61 // requested. See below for an example.
63 var results map[string]interface{}
65 params := arvadosclient.Dict{"limit": 5}
67 err = arv.List("collections", params, &results)
69 log.Fatalf("error querying collections", err.Error())
72 printArvadosResults(results)
75 // *********************************************************
76 // Print some fields from the first two collections returned.
78 // We also print manifest_test, which has to be explicitly requested.
81 collection_fields_wanted := []string{"manifest_text", "owner_uuid", "uuid"}
82 params = arvadosclient.Dict{"limit": 2, "select": collection_fields_wanted}
84 err = arv.List("collections", params, &results)
86 log.Fatalf("error querying collections", err.Error())
89 printArvadosResults(results)
93 // A helper method which will print out a result map returned by
95 func printArvadosResults(results map[string]interface{}) {
96 for key, value := range results {
97 // "items", if it exists, holds a map.
98 // So we print it prettily below.
100 fmt.Println(key, ":", value)
104 if value, ok := results["items"]; ok {
105 items := value.([]interface{})
106 for index, item := range items {
107 fmt.Println("=========== ", index, " ===========")
108 item_map := item.(map[string]interface{})
109 if len(item_map) == 0 {
110 fmt.Println("item", index, ": empty map")
112 for k, v := range item_map {
113 fmt.Println(index, k, ":", v)