Browse Source

add ipfs pubsub methods

batching_initial_approach
imw 5 years ago
parent
commit
6ad2f16c24
1 changed files with 21 additions and 2 deletions
  1. +21
    -2
      data/data.go

+ 21
- 2
data/data.go

@ -8,7 +8,7 @@ import (
shell "github.com/ipfs/go-ipfs-api" shell "github.com/ipfs/go-ipfs-api"
) )
func publish(object []byte) (string) {
func publish(object []byte) string {
sh := shell.NewShell("localhost:5001") sh := shell.NewShell("localhost:5001")
cid, err := sh.Add(bytes.NewBuffer(object)) cid, err := sh.Add(bytes.NewBuffer(object))
if err != nil { if err != nil {
@ -28,7 +28,7 @@ func pin(path string) {
} }
func retrieve(hash string) ([]byte){
func retrieve(hash string) []byte {
sh := shell.NewShell("localhost:5001") sh := shell.NewShell("localhost:5001")
reader, err := sh.Cat(hash) reader, err := sh.Cat(hash)
if err != nil { if err != nil {
@ -42,3 +42,22 @@ func retrieve(hash string) ([]byte){
} }
return content return content
} }
func PsSubscribe(topic string) *shell.PubSubSubscription {
sh := shell.NewShell("localhost:5001")
sub, err := sh.PubSubSubscribe(topic)
if err != nil {
fmt.Fprintf(os.Stderr, "error: %s", err)
os.Exit(1)
}
return sub
}
func PsPublish(topic, data string) {
sh := shell.NewShell("localhost:5001")
err := sh.PubSubPublish(topic, data)
if err != nil {
fmt.Fprintf(os.Stderr, "error: %s", err)
os.Exit(1)
}
}

Loading…
Cancel
Save