Skip to content

Commit 77b7624

Browse files
authored
Merge pull request #59 from n0-computer/go_sdk
document go module
2 parents d8009c7 + c60dc7c commit 77b7624

File tree

22 files changed

+648
-68
lines changed

22 files changed

+648
-68
lines changed

command-code-examples/commands.mjs

Lines changed: 62 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,25 @@
11

22
const doc = [
33
{
4-
name: 'doc switch',
5-
description: 'Set the active document (only works within the Iroh console).',
6-
slug: 'doc-switch',
7-
arguments: [
8-
{ name: 'id', necessity: 'required', description: 'The [identifier](/docs/layers/documents#document-identifiers) of the document to switch to.' },
9-
],
4+
name: 'doc list',
5+
description: 'List documents on this node.',
6+
slug: 'doc-list',
107
examples: {
11-
console: `> doc new
12-
ktrygcpxealfdtfmohw66nb2keivu52opk65cyj4j7jy7wior7ea
13-
14-
> doc switch ktrygcpxealfdtfmohw66nb2keivu52opk65cyj4j7jy7wior7ea
15-
16-
doc:ktrygcpx
17-
>`,
8+
console: `> doc list
9+
tiqpal5qnrb3idy7g4n7hnh5esex7zu6jtqyuwt6hr4iq2nnlpua
10+
3ogcanavjfehmoeuf3jkel5pmbv2bpdwybvzt7xzk5sgbub72mia
11+
njszszvgpziwnxqnsi32nmc7j2czs2rnj3m7czavudurqxld3nbq`,
1812
}
1913
},
2014
{
2115
name: 'doc new',
22-
description: 'Create a new blank document.',
16+
description: 'Create a new blank document.',
2317
slug: 'doc-new',
2418
examples: {
2519
console: `> doc new
2620
ktrygcpxealfdtfmohw66nb2keivu52opk65cyj4j7jy7wior7ea`,
2721
}
2822
},
29-
{
30-
name: 'doc join',
31-
description: 'Join a document from a ticket.',
32-
slug: 'doc-join',
33-
arguments: [
34-
{ name: 'ticket', necessity: 'required', description: 'The ticket to join a document. Create a ticket with \'doc share\'.' },
35-
{ name: 'switch', necessity: '', description: 'Switch to the joined document (only in the iroh console).'}
36-
],
37-
examples: {
38-
console: `> doc join --switch 6tcadaassjgjfmivyaycuads6ek4asma3qacdtvs6waaaaaaaaaanctrkxaetag4aaq45mxvqmruwqvq5l5vc4kvybeybxaaehhlf5mmh72ojerj4e2tcvoajganyabbz2zplnqhpyekxzhlfzyvlqcai55pmzg4d3x34mcpuydxoq4t5ec66zp3k3ouxwadxky745i3dwrhqcig3rqqdifkjjb3drfbo2krc7l3anoqly5wanom756kxmrqnap
39-
tiqpal5qnrb3idy7g4n7hnh5esex7zu6jtqyuwt6hr4iq2nnlpua`,
40-
}
41-
},
42-
{
43-
name: 'doc list',
44-
description: 'List documents on this node.',
45-
slug: 'doc-list',
46-
examples: {
47-
console: `> doc list
48-
tiqpal5qnrb3idy7g4n7hnh5esex7zu6jtqyuwt6hr4iq2nnlpua
49-
3ogcanavjfehmoeuf3jkel5pmbv2bpdwybvzt7xzk5sgbub72mia
50-
njszszvgpziwnxqnsi32nmc7j2czs2rnj3m7czavudurqxld3nbq`,
51-
}
52-
},
53-
{
54-
name: 'doc share',
55-
description: 'Share a document with peers.',
56-
slug: 'doc-share',
57-
arguments: [
58-
{ name: 'mode', necessity: 'required', description: 'One of \'read\' for Read-only access or \'write\' for Write access.' },
59-
{ name: 'doc', necessity: 'required', description: 'Document to share. In the console the current document is used when no `--doc` is provided.' }
60-
],
61-
examples: {
62-
console: `# switch to a specific doc
63-
> doc switch njszszvgpziwnxqnsi32nmc7j2czs2rnj3m7czavudurqxld3nbq
64-
Active doc is now njszszvg…
65-
66-
doc: njszszvg…
67-
68-
> doc share write
69-
xvqmruwqvq5l5vc4kvybeybxaaehhlf5mmh72ojerj4e2tcvoajganyabbz2zplnqhpyekxzhlfzyvlqcaidiaglyldhfvq4xeaa5cqswdistl2hje3c24biacig3rqqdifkjjb3drfbo2krc7l3anoqly5wanom756kxmrqnap6tcadaassjgjfmivyaycuads6ek4asma3qacdtvs6waaaaaaaaaanctrkxaetag4aaq45mprsyystlwe66cs
70-
71-
# or use --doc flag to get the ticket for a specific doc
72-
> doc share write --doc 3ogcanavjfehmoeuf3jkel5pmbv2bpdwybvzt7xzk5sgbub72mia
73-
gjfmivyaycuads6ek4asma3qacdtvs6waaaaaaaaaanctrkxaetag4aaq45mprsyystlwe66csxvqmruwqvq5l5vc4kvybeybxaaehhlf5mmh72ojerj4e2tcvoajganyabbz2zplnqhpyekxzhljfkldiajjkannnnjiejfkldkaskjlxi0jfwoqppiemxclpilkdipljqhixkkwmhziufkhablskhdjjlllqwoooqusiuypwouuuuippmjkk
74-
` }
75-
},
7623
{
7724
name: 'doc set',
7825
description: 'Set an entry in a document',
@@ -164,6 +111,59 @@ author:i3vpd4e7… doc:njszszvg…
164111
@i3vpd4e7…: foo = 6lujp3wx… (3 B)`,
165112
}
166113
},
114+
{
115+
name: 'doc share',
116+
description: 'Share a document with peers.',
117+
slug: 'doc-share',
118+
arguments: [
119+
{ name: 'mode', necessity: 'required', description: 'One of \'read\' for Read-only access or \'write\' for Write access.' },
120+
{ name: 'doc', necessity: 'required', description: 'Document to share. In the console the current document is used when no `--doc` is provided.' }
121+
],
122+
examples: {
123+
console: `# switch to a specific doc
124+
> doc switch njszszvgpziwnxqnsi32nmc7j2czs2rnj3m7czavudurqxld3nbq
125+
Active doc is now njszszvg…
126+
127+
doc: njszszvg…
128+
129+
> doc share write
130+
xvqmruwqvq5l5vc4kvybeybxaaehhlf5mmh72ojerj4e2tcvoajganyabbz2zplnqhpyekxzhlfzyvlqcaidiaglyldhfvq4xeaa5cqswdistl2hje3c24biacig3rqqdifkjjb3drfbo2krc7l3anoqly5wanom756kxmrqnap6tcadaassjgjfmivyaycuads6ek4asma3qacdtvs6waaaaaaaaaanctrkxaetag4aaq45mprsyystlwe66cs
131+
132+
# or use --doc flag to get the ticket for a specific doc
133+
> doc share write --doc 3ogcanavjfehmoeuf3jkel5pmbv2bpdwybvzt7xzk5sgbub72mia
134+
gjfmivyaycuads6ek4asma3qacdtvs6waaaaaaaaaanctrkxaetag4aaq45mprsyystlwe66csxvqmruwqvq5l5vc4kvybeybxaaehhlf5mmh72ojerj4e2tcvoajganyabbz2zplnqhpyekxzhljfkldiajjkannnnjiejfkldkaskjlxi0jfwoqppiemxclpilkdipljqhixkkwmhziufkhablskhdjjlllqwoooqusiuypwouuuuippmjkk
135+
` }
136+
},
137+
{
138+
name: 'doc join',
139+
description: 'Join a document from a ticket.',
140+
slug: 'doc-join',
141+
arguments: [
142+
{ name: 'ticket', necessity: 'required', description: 'The ticket to join a document. Create a ticket with \'doc share\'.' },
143+
{ name: 'switch', necessity: '', description: 'Switch to the joined document (only in the iroh console).'}
144+
],
145+
examples: {
146+
console: `> doc join --switch 6tcadaassjgjfmivyaycuads6ek4asma3qacdtvs6waaaaaaaaaanctrkxaetag4aaq45mxvqmruwqvq5l5vc4kvybeybxaaehhlf5mmh72ojerj4e2tcvoajganyabbz2zplnqhpyekxzhlfzyvlqcai55pmzg4d3x34mcpuydxoq4t5ec66zp3k3ouxwadxky745i3dwrhqcig3rqqdifkjjb3drfbo2krc7l3anoqly5wanom756kxmrqnap
147+
tiqpal5qnrb3idy7g4n7hnh5esex7zu6jtqyuwt6hr4iq2nnlpua`,
148+
}
149+
},
150+
{
151+
name: 'doc switch',
152+
description: 'Set the active document (only works within the Iroh console).',
153+
slug: 'doc-switch',
154+
arguments: [
155+
{ name: 'id', necessity: 'required', description: 'The [identifier](/docs/layers/documents#document-identifiers) of the document to switch to.' },
156+
],
157+
examples: {
158+
console: `> doc new
159+
ktrygcpxealfdtfmohw66nb2keivu52opk65cyj4j7jy7wior7ea
160+
161+
> doc switch ktrygcpxealfdtfmohw66nb2keivu52opk65cyj4j7jy7wior7ea
162+
163+
doc:ktrygcpx
164+
>`,
165+
}
166+
},
167167
]
168168

169169
const author = [
@@ -185,7 +185,7 @@ author:wkl4cgry…
185185
}
186186
},
187187
{
188-
name: 'author list',
188+
name: 'author list',
189189
description: 'List authors.',
190190
slug: 'author-list',
191191
examples: {
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/n0-computer/iroh-ffi/iroh"
7+
)
8+
9+
func main() {
10+
node, err := iroh.NewIrohNode()
11+
if err != nil {
12+
panic(err)
13+
}
14+
15+
if _, err := node.AuthorNew(); err != nil {
16+
panic(err)
17+
}
18+
19+
authors, err := node.AuthorList()
20+
if err != nil {
21+
panic(err)
22+
}
23+
24+
for _, author := range authors {
25+
fmt.Println(author.ToString())
26+
}
27+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/n0-computer/iroh-ffi/iroh"
7+
)
8+
9+
func main() {
10+
node, err := iroh.NewIrohNode()
11+
if err != nil {
12+
panic(err)
13+
}
14+
15+
author, err := node.AuthorNew()
16+
if err != nil {
17+
panic(err)
18+
}
19+
fmt.Printf("Created author %s\n", author.ToString())
20+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/n0-computer/iroh-ffi/iroh"
7+
)
8+
9+
func main() {
10+
node, err := iroh.NewIrohNode()
11+
if err != nil {
12+
// real programs handle errors!
13+
panic(err)
14+
}
15+
16+
author, err := node.AuthorNew()
17+
if err != nil {
18+
panic(err)
19+
}
20+
fmt.Printf("Created author %s\n", author.ToString())
21+
22+
doc, err := node.DocNew()
23+
if err != nil {
24+
panic(err)
25+
}
26+
fmt.Printf("Created document %s\n", doc.Id())
27+
28+
hash, err := doc.SetBytes(author, []byte("go"), []byte("says hello"))
29+
if err != nil {
30+
panic(err)
31+
}
32+
fmt.Printf("Inserted %s\n", hash.ToString())
33+
34+
content, err := doc.GetContentBytes(hash)
35+
if err != nil {
36+
panic(err)
37+
}
38+
fmt.Printf("Got content %q\n", string(content))
39+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/n0-computer/iroh-ffi/iroh"
7+
)
8+
9+
// you'll need to get a ticket from somewhere, see the `doc share` command documentation
10+
// for details. This ticket will fail to join, but is a valid ticket.
11+
const ticketString = "sdx7wazju2rysqydgfpmhqkrluc5lbcuainravjipwmbl7r3k3uqcigncyopdcnooufnteu5vuatpzhoqrml35ifgyuozr6kwhjiz4jxyaaqcbiajbmsainmsmbqcjqaibavg5hiaaaaaaaaaaabad47sebqbqfiiqzkzeydadakqrckvsjqgajgabaecu3u5aaaaaaaaaaaaeagt6iqg"
12+
13+
func main() {
14+
node, err := iroh.NewIrohNode()
15+
if err != nil {
16+
panic(err)
17+
}
18+
19+
ticket, err := iroh.DocTicketFromString(ticketString)
20+
if err != nil {
21+
panic(err)
22+
}
23+
24+
doc, err := node.DocJoin(ticket)
25+
if err != nil {
26+
panic(err)
27+
}
28+
29+
fmt.Println("Joined doc: %s", doc.Id())
30+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/n0-computer/iroh-ffi/iroh"
7+
)
8+
9+
func main() {
10+
node, err := iroh.NewIrohNode()
11+
if err != nil {
12+
panic(err)
13+
}
14+
15+
author, err := node.AuthorNew()
16+
if err != nil {
17+
panic(err)
18+
}
19+
20+
doc, err := node.DocNew()
21+
if err != nil {
22+
panic(err)
23+
}
24+
fmt.Printf("Created document %s\n", doc.Id())
25+
26+
for i, key := range []string{"a", "b", "c"} {
27+
if _, err := doc.SetBytes(author, []byte(key), []byte(fmt.Sprintf("%d", i))); err != nil {
28+
panic(err)
29+
}
30+
}
31+
32+
keys, err := doc.Keys()
33+
if err != nil {
34+
panic(err)
35+
}
36+
37+
fmt.Println("Keys:")
38+
for _, key := range keys {
39+
content, err := doc.GetContentBytes(key)
40+
if err != nil {
41+
panic(err)
42+
}
43+
fmt.Printf("%q : %q (hash: %s)\n", string(key.Key()), string(content), key.Hash().ToString())
44+
}
45+
// Output:
46+
// Created document 7hgonoxdjzlwtuicfyou24l5nhv3bmvzhyeq6v2er66ekrpvhotq
47+
// Keys:
48+
// "a" : "0" (hash: bafkr4icnazyvhldstjfh5arazf4tl752m5ehqygvqkmm52zdqzbwtbt5t4)
49+
// "b" : "1" (hash: bafkr4igwhpm2qjvpsha75i3rszngjyi64ihrhzdll5jmlgibcntalm5eq4)
50+
// "c" : "2" (hash: bafkr4iebh2nxfekb47zyll5aulin6ptmg6e6ij774sxo6vtkkzn4r4x6hu)
51+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/n0-computer/iroh-ffi/iroh"
7+
)
8+
9+
func main() {
10+
node, err := iroh.NewIrohNode()
11+
if err != nil {
12+
// real programs handle errors!
13+
panic(err)
14+
}
15+
16+
doc, err := node.DocNew()
17+
if err != nil {
18+
panic(err)
19+
}
20+
fmt.Printf("Created document %s\n", doc.Id())
21+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/n0-computer/iroh-ffi/iroh"
7+
)
8+
9+
func main() {
10+
node, err := iroh.NewIrohNode()
11+
if err != nil {
12+
// real programs handle errors!
13+
panic(err)
14+
}
15+
16+
author, err := node.AuthorNew()
17+
if err != nil {
18+
panic(err)
19+
}
20+
fmt.Printf("Created author %s\n", author.ToString())
21+
22+
doc, err := node.DocNew()
23+
if err != nil {
24+
panic(err)
25+
}
26+
fmt.Printf("Created document %s\n", doc.Id())
27+
28+
hash, err := doc.SetBytes(author, []byte("go"), []byte("says hello"))
29+
if err != nil {
30+
panic(err)
31+
}
32+
fmt.Printf("Inserted %s\n", hash.ToString())
33+
34+
content, err := doc.GetContentBytes(hash)
35+
if err != nil {
36+
panic(err)
37+
}
38+
fmt.Printf("Got content %q\n", string(content))
39+
}

0 commit comments

Comments
 (0)