Skip to content

Instantly share code, notes, and snippets.

@whyrusleeping
Created March 1, 2016 20:52
Show Gist options
  • Save whyrusleeping/f5ef3f0adeb0ce59d3bd to your computer and use it in GitHub Desktop.
Save whyrusleeping/f5ef3f0adeb0ce59d3bd to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"os"
key "github.com/ipfs/go-ipfs/blocks/key"
core "github.com/ipfs/go-ipfs/core"
fsrepo "github.com/ipfs/go-ipfs/repo/fsrepo"
"golang.org/x/net/context"
)
func main() {
if len(os.Args) < 2 {
fmt.Println("Please give an ipfs hash as an argument")
return
}
objkey := key.B58KeyDecode(os.Args[1])
if objkey == "" {
fmt.Println("incorrectly formatted key")
return
}
// Basic ipfsnode setup
r, err := fsrepo.Open("~/.ipfs")
if err != nil {
panic(err)
}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
cfg := &core.BuildCfg{
Repo: r,
Online: true,
}
nd, err := core.NewNode(ctx, cfg)
if err != nil {
panic(err)
}
objnode, err := nd.DAG.Get(ctx, objkey)
if err != nil {
panic(err)
}
fmt.Println("got an object!")
fmt.Println("its links: ", objnode.Links)
fmt.Println("its data: ", objnode.Data)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment