7 // Our examples don't use keepclient, but they do use fmt and log to
12 "git.curoverse.com/arvados.git/sdk/go/arvadosclient"
19 // ********************************
20 // Set up an API client user agent.
23 arv, err := arvadosclient.MakeArvadosClient()
25 log.Fatalf("Error setting up arvados client %s", err.Error())
29 // *****************************************
30 // Print the full name of the current user.
34 // Remember to start each field name with a capital letter,
35 // otherwise it won't get populated by the arvados client because
36 // the field will be invisible to it.
37 Uuid string `json:"uuid"`
38 FullName string `json:"full_name"`
42 err = arv.Call("GET", "users", "", "current", nil, &u)
45 log.Fatalf("error querying current user", err.Error())
48 log.Printf("Logged in as %s (uuid %s)", u.FullName, u.Uuid)
51 // ********************************************************
52 // Print all fields from the first five collections returned.
54 // Note that some fields, are not returned by default and have to be
55 // requested. See below for an example.
57 var results map[string]interface{}
59 params := arvadosclient.Dict{"limit": 5}
61 err = arv.List("collections", params, &results)
63 log.Fatalf("error querying collections", err.Error())
66 printArvadosResults(results)
69 // *********************************************************
70 // Print some fields from the first two collections returned.
72 // We also print manifest_test, which has to be explicitly requested.
75 collection_fields_wanted := []string{"manifest_text", "owner_uuid", "uuid"}
76 params = arvadosclient.Dict{"limit": 2, "select": collection_fields_wanted}
78 err = arv.List("collections", params, &results)
80 log.Fatalf("error querying collections", err.Error())
83 printArvadosResults(results)
87 // A helper method which will print out a result map returned by
89 func printArvadosResults(results map[string]interface{}) {
90 for key, value := range results {
91 // "items", if it exists, holds a map.
92 // So we print it prettily below.
94 fmt.Println(key, ":", value)
98 if value, ok := results["items"]; ok {
99 items := value.([]interface{})
100 for index, item := range items {
101 fmt.Println("=========== ", index, " ===========")
102 item_map := item.(map[string]interface{})
103 if len(item_map) == 0 {
104 fmt.Println("item", index, ": empty map")
106 for k, v := range item_map {
107 fmt.Println(index, k, ":", v)