arnaucube
arnaucube/go-dvotePublic Self-hosted repository
add ipfs pubsub methods
imw imw@0x539.lol
Fri, 28 Dec 2018 12:37:36 +0100
commit

6ad2f16c24b830b234861c62bf6059786de963c6

parent

b4b687eeda137bbe95dcf74efb2250830cdcf38d

1 files changed, 21 insertions(+), 2 deletions(-)

jump to
M data/data.go → data/data.go

@@ -8,7 +8,7 @@ "io/ioutil"

shell "github.com/ipfs/go-ipfs-api" ) -func publish(object []byte) (string) { +func publish(object []byte) string { sh := shell.NewShell("localhost:5001") cid, err := sh.Add(bytes.NewBuffer(object)) if err != nil {

@@ -28,7 +28,7 @@ }

} -func retrieve(hash string) ([]byte){ +func retrieve(hash string) []byte { sh := shell.NewShell("localhost:5001") reader, err := sh.Cat(hash) if err != nil {

@@ -42,3 +42,22 @@ os.Exit(1)

} 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) + } +}