Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
ld
go-ld-prime
Commits
17df5e5b
Commit
17df5e5b
authored
Jul 14, 2021
by
Eric Myhre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix example names so they render on go.pkg.dev.
parent
b7347f19
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
11 deletions
+20
-11
examples_test.go
examples_test.go
+12
-3
linkingExamples_test.go
linkingExamples_test.go
+8
-8
No files found.
examples_test.go
View file @
17df5e5b
...
...
@@ -9,8 +9,12 @@ import (
basicnode
"github.com/ipld/go-ipld-prime/node/basic"
)
func
ExampleCreateDataAndMarshal
()
{
// Example_createDataAndMarshal shows how you can feed data into a NodeBuilder,
// and also how to then hand that to an Encoder.
//
// Often you'll encoding implicitly through a LinkSystem.Store call instead,
// but you can do it directly, too.
func
Example_createDataAndMarshal
()
{
np
:=
basicnode
.
Prototype
.
Any
// Pick a prototype: this is how we decide what implementation will store the in-memory data.
nb
:=
np
.
NewBuilder
()
// Create a builder.
ma
,
_
:=
nb
.
BeginMap
(
2
)
// Begin assembling a map.
...
...
@@ -30,7 +34,12 @@ func ExampleCreateDataAndMarshal() {
// }
}
func
ExampleUnmarshalData
()
{
// Example_unmarshalData shows how you can use a Decoder
// and a NodeBuilder (or NodePrototype) together to do unmarshalling.
//
// Often you'll do this implicitly through a LinkSystem.Load call instead,
// but you can do it directly, too.
func
Example_unmarshalData
()
{
serial
:=
strings
.
NewReader
(
`{"hey":"it works!","yes": true}`
)
np
:=
basicnode
.
Prototype
.
Any
// Pick a stle for the in-memory data.
...
...
linkingExamples_test.go
View file @
17df5e5b
...
...
@@ -15,8 +15,8 @@ import (
// storage is a map where we'll store serialized IPLD data.
//
// Example
CreatingLink
will put data into this;
// ExampleL
oadingLink
will read out from it.
// Example
LinkSystem_Store
will put data into this;
// ExampleL
inkSystem_Load
will read out from it.
//
// In a real program, you'll probably make functions to load and store from disk,
// or some network storage, or... whatever you want, really :)
...
...
@@ -25,7 +25,7 @@ var store = storage.Memory{}
// TODO: These examples are really heavy on CIDs and the multicodec and multihash magic tables.
// It would be good to have examples that create and use less magical LinkSystem constructions, too.
func
Example
StoringLink
()
{
func
Example
LinkSystem_Store
()
{
// Creating a Link is done by choosing a concrete link implementation (typically, CID),
// getting a LinkSystem that knows how to work with that, and then using the LinkSystem methods.
...
...
@@ -89,19 +89,19 @@ func ExampleStoringLink() {
// concrete type: `cidlink.Link`
}
func
ExampleL
oadingLink
()
{
// Let's say we want to load this link (it's the same one we
just
created in
the e
xample
abov
e).
func
ExampleL
inkSystem_Load
()
{
// Let's say we want to load this link (it's the same one we created in
E
xample
LinkSystem_Stor
e).
cid
,
_
:=
cid
.
Decode
(
"bafyrgqhai26anf3i7pips7q22coa4sz2fr4gk4q4sqdtymvvjyginfzaqewveaeqdh524nsktaq43j65v22xxrybrtertmcfxufdam3da3hbk"
)
lnk
:=
cidlink
.
Link
{
cid
}
// Let's get a LinkSystem. We're going to be working with CID links,
// so let's get the default LinkSystem that's ready to work with those.
// (This is the same as we did in Example
StoringLink
.)
// (This is the same as we did in Example
LinkSystem_Store
.)
lsys
:=
cidlink
.
DefaultLinkSystem
()
// We need somewhere to go looking for any of the data we might want to load!
// We'll use an in-memory store for this. (It's a package scoped variable.)
// (This particular memory store was filled with the data we'll load earlier, during Example
StoringLink
.)
// (This particular memory store was filled with the data we'll load earlier, during Example
LinkSystem_Store
.)
// You can use any kind of storage system here;
// you just need a function that conforms to the ipld.BlockReadOpener interface.
lsys
.
StorageReadOpener
=
(
&
store
)
.
OpenRead
...
...
@@ -113,7 +113,7 @@ func ExampleLoadingLink() {
// Before we use the LinkService, NOTE:
// There's a side-effecting import at the top of the file. It's for the dag-cbor codec.
// See the comments in Example
StoringLink
for more discussion of this and why it's important.
// See the comments in Example
LinkSystem_Store
for more discussion of this and why it's important.
// Apply the LinkSystem, and ask it to load our link!
n
,
err
:=
lsys
.
Load
(
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment