Merge branch '8784-dir-listings'
[arvados.git] / doc / sdk / go / example.html.textile.liquid
1 ---
2 layout: default
3 navsection: sdk
4 navmenu: Python
5 title: Examples
6 ...
7 {% comment %}
8 Copyright (C) The Arvados Authors. All rights reserved.
9
10 SPDX-License-Identifier: CC-BY-SA-3.0
11 {% endcomment %}
12
13 See "Arvados GoDoc":https://godoc.org/git.curoverse.com/arvados.git/sdk/go for detailed documentation.
14
15 In these examples, the site prefix is @aaaaa@.
16
17 h2.  Initialize SDK
18
19 <pre>
20 import (
21   "git.curoverse.com/arvados.git/sdk/go/arvados"
22   "git.curoverse.com/arvados.git/sdk/go/arvadosclient"
23 }
24
25 func main() {
26   arv, err := arvadosclient.MakeArvadosClient()
27   if err != nil {
28     log.Fatalf("Error setting up arvados client %s", err.Error())
29   }
30 }
31 </pre>
32
33 h2. create
34
35 <pre>
36   var collection arvados.Collection
37   err := api.Create("collections", Dict{"collection": Dict{"name": "create example"}}, &collection)
38 </pre>
39
40 h2. delete
41
42 <pre>
43   var collection arvados.Collection
44   err := api.Delete("collections", "aaaaa-4zz18-ccccccccccccccc", Dict{}, &collection)
45 </pre>
46
47 h2. get
48
49 <pre>
50   var collection arvados.Collection
51   err := api.Get("collections", "aaaaa-4zz18-ccccccccccccccc", Dict{}, &collection)
52 </pre>
53
54 h2. list
55
56 <pre>
57   var collection arvados.Collection
58   err := api.List("collections", Dict{}, &collection)
59 </pre>
60
61 h2. update
62
63 <pre>
64   var collection arvados.Collection
65   err := api.Update("collections", "aaaaa-4zz18-ccccccccccccccc", Dict{"collection": Dict{"name": "update example"}}, &collection)
66 </pre>
67
68 h2. Get current user
69
70 <pre>
71   var user arvados.User
72   err := api.Get("users", "current", Dict{}, &user)
73 </pre>
74
75 h2. Example program
76
77 You can save this source as a .go file and run it:
78
79 <notextile>{% code 'example_sdk_go' as go %}</notextile>
80
81 A few more usage examples can be found in the "services/keepproxy":https://dev.arvados.org/projects/arvados/repository/revisions/master/show/services/keepproxy and "sdk/go/keepclient":https://dev.arvados.org/projects/arvados/repository/revisions/master/show/sdk/go/keepclient directories in the arvados source tree.