Documentation
¶
Index ¶
- type AddResult
- type Cid
- type IPFS
- func (f *IPFS) Add(ctx context.Context, r io.Reader) (*AddResult, error)
- func (f *IPFS) Cat(ctx context.Context, path string) (io.ReadCloser, error)
- func (f *IPFS) CatBytes(ctx context.Context, path string) (bs []byte, err error)
- func (f *IPFS) DagGetLinks(ctx context.Context, cid Cid) ([]Link, error)
- func (f *IPFS) DagPutLinks(ctx context.Context, links []Link) (Cid, error)
- func (f *IPFS) ObjectStat(ctx context.Context, path string) (*ObjectStat, error)
- type Link
- type ObjectStat
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AddResult ¶
AddResult contains result of AddResult command
type Cid ¶
type Cid string
Cid represents a self-describing content adressed
func (Cid) Defined ¶
Defined returns true if a Cid is defined Calling any other methods on an undefined Cid will result in undefined behavior.
func (Cid) MarshalJSON ¶
MarshalJSON procudes a JSON representation of a Cid, which looks as follows:
{ "/": "<cid-string>" }
Note that this formatting comes from the IPLD specification (https://github.com/ipld/specs/tree/master/ipld)
func (*Cid) UnmarshalJSON ¶
UnmarshalJSON parses the JSON representation of a Cid.
type IPFS ¶
type IPFS struct {
// contains filtered or unexported fields
}
IPFS provides limited functionality to interact with the IPFS (https://ipfs.io)
func NewWithClient ¶
NewWithClient creates new instance of IPFS from the provided url and http.Client
func (*IPFS) Cat ¶
Cat the content at the given path. Callers need to drain and close the returned reader after usage.
func (*IPFS) DagGetLinks ¶
DagGetLinks gets directory links.
func (*IPFS) DagPutLinks ¶
DagPutLinks puts directory containing links and returns Cid of directory.
Example ¶
package main
import (
"context"
"fmt"
"net/http"
"strings"
"github.com/dnaeon/go-vcr/recorder"
"github.com/monetha/go-verifiable-data/ipfs"
)
func main() {
// start http recorder
r, err := recorder.New("fixtures/dag-links")
if err != nil {
panic(err)
}
defer func() { _ = r.Stop() }() // Make sure recorder is stopped once done with it
c, err := ipfs.NewWithClient("https://ipfs.infura.io:5001", &http.Client{Transport: r})
if err != nil {
panic(err)
}
ctx := context.Background()
file1, err := c.Add(ctx, strings.NewReader("file 1 content"))
if err != nil {
panic(err)
}
fmt.Printf("file1.txt: %v\n", file1)
file2, err := c.Add(ctx, strings.NewReader("file 2 content"))
if err != nil {
panic(err)
}
fmt.Printf("file2.txt: %v\n", file2)
subDir, err := c.DagPutLinks(ctx, []ipfs.Link{
file1.ToLink("file1.txt"),
file2.ToLink("file2.txt"),
})
if err != nil {
panic(err)
}
fmt.Printf("subdir: Hash: %v\n", subDir.String())
subDirStat, err := c.ObjectStat(ctx, subDir.String())
if err != nil {
panic(err)
}
fmt.Printf("subdir: Size: %v\n", subDirStat.CumulativeSize)
readmeFile, err := c.Add(ctx, strings.NewReader("README blah blah blah..."))
if err != nil {
panic(err)
}
fmt.Printf("readme.txt: %v\n", readmeFile)
rootDir, err := c.DagPutLinks(ctx, []ipfs.Link{
subDir.ToLink("subdir", subDirStat.CumulativeSize),
readmeFile.ToLink("README.txt"),
})
if err != nil {
panic(err)
}
fmt.Printf("rootdir: Hash: %v\n", rootDir.String())
rc, err := c.CatBytes(ctx, rootDir.String()+"/subdir/file1.txt")
if err != nil {
panic(err)
}
file1Content := string(rc)
fmt.Println(file1Content)
}
Output: file1.txt: Hash: QmSFEbC6Y17cdti7damkjoqESWftkyfSXjdKDQqnf4ECV7 Size: 22 file2.txt: Hash: QmVssUfKob8KkUyUiwzoGqNTKqyaEXfqxeGiUJ7ZGyfPLV Size: 22 subdir: Hash: QmaRt7pb5LE7991M94XzVCcZgUKPLoihD941GyFSuYBQ9Y subdir: Size: 150 readme.txt: Hash: QmeQVyGZQbArEEzukCAXbNbLBBwiBwD4E1WinEeAVw1dZ8 Size: 32 rootdir: Hash: QmZgrVVH6Dp4MR4FoF5npDTtJzLneH2KvxoPHixAiucVJH file 1 content
func (*IPFS) ObjectStat ¶
ObjectStat returns information about the dag node
type Link ¶
type Link struct {
// multihash of the target object
Cid Cid `json:"Cid"`
// utf string name. should be unique per object
Name string `json:"Name"`
// cumulative size of target object
Size uint64 `json:"Size"`
}
Link represents an IPFS Merkle DAG Link between Nodes.
type ObjectStat ¶
type ObjectStat struct {
Hash string `json:"Hash"`
NumLinks uint64 `json:"NumLinks"`
BlockSize uint64 `json:"BlockSize"`
LinksSize uint64 `json:"LinksSize"`
DataSize uint64 `json:"DataSize"`
CumulativeSize uint64 `json:"CumulativeSize"`
}
ObjectStat provides information about dag nodes