Skip to content

Instantly share code, notes, and snippets.

@tobowers tobowers/main.go
Created Aug 23, 2018

Embed
What would you like to do?
package main
import (
"bytes"
"context"
"fmt"
"io/ioutil"
"log"
"github.com/ipsn/go-ipfs/core"
"github.com/ipsn/go-ipfs/core/coreunix"
)
func main() {
node, err := core.NewNode(context.TODO(), &core.BuildCfg{Online: true})
if err != nil {
log.Fatalf("Failed to start IPFS node: %v", err)
}
dataa := ioutil.NopCloser(bytes.NewBufferString("testfileA"))
str, err := coreunix.Add(node, dataa)
if err != nil {
panic(err)
}
fmt.Printf("str: %s\n", str)
reader, err := coreunix.Cat(context.TODO(), node, str)
if err != nil {
log.Fatalf("Failed: %v", err)
}
blob, err := ioutil.ReadAll(reader)
if err != nil {
log.Fatalf("Failed to retrieve: %v", err)
}
fmt.Println(string(blob))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.