-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathipldcrud.go
More file actions
32 lines (27 loc) · 778 Bytes
/
ipldcrud.go
File metadata and controls
32 lines (27 loc) · 778 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package ipldcrud
import (
"fmt"
"os"
shell "github.com/ipfs/go-ipfs-api"
)
// InitShell is used to create a new IPFS Shell
func InitShell(ipfsURL string) *shell.Shell {
// Where your local node is running on localhost:5001
sh := shell.NewShell(ipfsURL)
return sh
}
// Set writes key-value data
func Set(sh *shell.Shell, data []byte) string {
// Dag PUT operation which will return the CID for futher access or pinning etc.
cid, err := sh.DagPut(data, "json", "cbor")
if err != nil {
fmt.Fprintf(os.Stderr, "error: %s", err)
os.Exit(1)
}
return cid
}
// Get handles READ operations of a DAG entry by CID, returning the corresponding value
func Get(sh *shell.Shell, ref, key string) (out interface{}, err error) {
err = sh.DagGet(ref+"/"+key, &out)
return
}