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 Uuid string `json:"uuid"`
35 FullName string `json:"full_name"`
39 err = arv.Call("GET", "users", "", "current", nil, &u)
42 log.Fatalf("error querying current user", err.Error())
45 log.Printf("Logged in as %s (uuid %s)", u.FullName, u.Uuid)
48 // ********************************************************
49 // Print all fields from the first five collections returned.
51 // Note that some fields, are not returned by default and have to be
52 // requested. See below for an example.
54 var results map[string]interface{}
56 params := arvadosclient.Dict{"limit": 5}
58 err = arv.List("collections", params, &results)
60 log.Fatalf("error querying collections", err.Error())
63 printArvadosResults(results)
66 // *********************************************************
67 // Print some fields from the first two collections returned.
69 // We also print manifest_test, which has to be explicitly requested.
72 collection_fields_wanted := []string{"manifest_text", "owner_uuid", "uuid"}
73 params = arvadosclient.Dict{"limit": 2, "select": collection_fields_wanted}
75 err = arv.List("collections", params, &results)
77 log.Fatalf("error querying collections", err.Error())
80 printArvadosResults(results)
84 // A helper method which will print out a result map returned by
86 func printArvadosResults(results map[string]interface{}) {
87 for key, value := range results {
88 // "items", if it exists, holds a map.
89 // So we print it prettily below.
91 fmt.Println(key, ":", value)
95 if value, ok := results["items"]; ok {
96 items := value.([]interface{})
97 for index, item := range items {
98 fmt.Println("=========== ", index, " ===========")
99 item_map := item.(map[string]interface{})
100 if len(item_map) == 0 {
101 fmt.Println("item", index, ": empty map")
103 for k, v := range item_map {
104 fmt.Println(index, k, ":", v)