1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: CC-BY-SA-3.0
11 // Our examples don't use keepclient, but they do use fmt and log to
16 "git.arvados.org/arvados.git/sdk/go/arvadosclient"
23 // ********************************
24 // Set up an API client user agent.
27 arv, err := arvadosclient.MakeArvadosClient()
29 log.Fatalf("Error setting up arvados client %s", err.Error())
33 // *****************************************
34 // Print the full name of the current user.
38 // Remember to start each field name with a capital letter,
39 // otherwise it won't get populated by the arvados client because
40 // the field will be invisible to it.
41 Uuid string `json:"uuid"`
42 FullName string `json:"full_name"`
46 err = arv.Call("GET", "users", "", "current", nil, &u)
49 log.Fatalf("error querying current user", err.Error())
52 log.Printf("Logged in as %s (uuid %s)", u.FullName, u.Uuid)
55 // ********************************************************
56 // Print all fields from the first five collections returned.
58 // Note that some fields, are not returned by default and have to be
59 // requested. See below for an example.
61 var results map[string]interface{}
63 params := arvadosclient.Dict{"limit": 5}
65 err = arv.List("collections", params, &results)
67 log.Fatalf("error querying collections", err.Error())
70 printArvadosResults(results)
73 // *********************************************************
74 // Print some fields from the first two collections returned.
76 // We also print manifest_test, which has to be explicitly requested.
79 collection_fields_wanted := []string{"manifest_text", "owner_uuid", "uuid"}
80 params = arvadosclient.Dict{"limit": 2, "select": collection_fields_wanted}
82 err = arv.List("collections", params, &results)
84 log.Fatalf("error querying collections", err.Error())
87 printArvadosResults(results)
91 // A helper method which will print out a result map returned by
93 func printArvadosResults(results map[string]interface{}) {
94 for key, value := range results {
95 // "items", if it exists, holds a map.
96 // So we print it prettily below.
98 fmt.Println(key, ":", value)
102 if value, ok := results["items"]; ok {
103 items := value.([]interface{})
104 for index, item := range items {
105 fmt.Println("=========== ", index, " ===========")
106 item_map := item.(map[string]interface{})
107 if len(item_map) == 0 {
108 fmt.Println("item", index, ": empty map")
110 for k, v := range item_map {
111 fmt.Println(index, k, ":", v)